From fe4e6d41d128783f4e2c264b5b08d0ff513e876a Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E7=BD=97=E6=AD=A3?= <1732036298@qq.com> Date: Tue, 19 Nov 2024 14:54:29 +0000 Subject: [PATCH] Merge #1429 into sdk602patch0911 from refs/changes/1429/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Code review from 罗正 * refs/changes/1429/head: (11 commits squashed) - applsit拨号盘实现:目前,滑动一下屏幕APP转动一次,后续优化为多次转动 - 解决倒计时界面内存泄漏问题 - Merge branch 'sdk602patch0911' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0911 - Merge branch 'sdk602patch0911' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0911 - 修改显示方式页面多国语言显示问题 - Merge branch 'sdk602patch0911' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0911 - 解决查找手表后变成长亮屏 - Merge branch 'sdk602patch0911' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0911 - 拨号盘样式,实现跟手滑动效果 - Merge branch 'sdk602patch0911' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0911 - 解决ChatGPT,设置Key后不能用问题 Signed-off-by: 罗正 <1732036298@qq.com> Reviewed-by: Caisking <3449750381@qq.com> Reviewed-by: 罗正 <1732036298@qq.com> Reviewed-by: aliyun8003852482 <1224667075@qq.com> Reviewed-by: snickersun@163.com Reviewed-by: aliyun6865282430 <1624952103@qq.com> Merged-by: Caisking <3449750381@qq.com> CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/1429 --- .../nativeui/aivoice/src/AiVoicePresenter.cpp | 23 +- .../nativeui/aivoice/src/AiVoiceView.cpp | 8 +- .../nativeui/applist/include/ApplistView.h | 5 +- .../nativeui/applist/src/ApplistView.cpp | 746 +++++++++++++++--- 4 files changed, 673 insertions(+), 109 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp index 8f21d1832..dbecef250 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-20 15:11:17 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-11-05 11:17:28 + * @LastEditTime: 2024-11-19 22:08:14 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp */ #include "AppViewIDs.h" @@ -129,7 +129,14 @@ namespace OHOS } else { - ChangeViewAndLogicOperator(AIVOICE_AIMODE_CONNECTING, AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID); + if(model->GetAiModelTextId() == STR_AIMODES_CHATGPT) //如果当前是在chatgpt模型*/ + { + ChangeViewAndLogicOperator(AIVOICE_AIMODE_CONNECTING, AIVOICE_NOTSETAPIKEYS); /*开始对话界面->API Keys notset界面*/ + } + else + { + ChangeViewAndLogicOperator(AIVOICE_AIMODE_CONNECTING, AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID); + } } } else @@ -325,12 +332,12 @@ namespace OHOS model->reset_ai_screen60s_timer_time(); /* -------------------------------------------------------------------------- */ - if ((viewId == AIVOICE_CHAT_BUTTON_VIEW_ID) && model->IsExistOpenAIAPIKeys() == false) // 如果点击的是(对话按钮)且未配置apikey - { - ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_NOTSETAPIKEYS); /*开始对话界面->API Keys notset界面*/ - return true; - } - else if (viewId == AIVOICE_APIKEYS_BUTTON_VIEW_ID) // 如果点击的是API Keys按钮(注:暂时不用) + // if ((viewId == AIVOICE_CHAT_BUTTON_VIEW_ID) && model->IsExistOpenAIAPIKeys() == false) // 如果点击的是(对话按钮)且未配置apikey + // { + // ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_NOTSETAPIKEYS); /*开始对话界面->API Keys notset界面*/ + // return true; + // } + if (viewId == AIVOICE_APIKEYS_BUTTON_VIEW_ID) // 如果点击的是API Keys按钮(注:暂时不用) { if (model->IsExistOpenAIAPIKeys() == true) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceView.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceView.cpp index a12d46886..8a589eac3 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceView.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-05-07 11:25:58 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-11-05 11:18:37 + * @LastEditTime: 2024-11-19 22:07:15 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AiVoiceView.cpp */ #include "aivoice/include/AiVoicePresenter.h" @@ -327,6 +327,7 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::aiModelImage is nullptr!!"); return false; } + upImage->SetVisible(false); return true; } @@ -356,7 +357,8 @@ namespace OHOS .y = 328, .w = 380, .h = 80, - .ViewId = AIVOICE_CHAT_BUTTON_VIEW_ID, + // .ViewId = AIVOICE_CHAT_BUTTON_VIEW_ID, + .ViewId = AIVOICE_START_CHAT_BUTTON_VIEW_ID, }; chatButton = AiVoiceViewButtonInit(buttonconfig); if (chatButton == nullptr) @@ -912,7 +914,7 @@ namespace OHOS // SetComponentVisibility(chatLabel, isAiModeChatGpt); // SetComponentVisibility(apiKeysButton, isAiModeChatGpt); // SetComponentVisibility(apiKeysLabel, isAiModeChatGpt); - SetComponentVisibility(upImage, isAiModeChatGpt); + // SetComponentVisibility(upImage, isAiModeChatGpt); // SetComponentVisibility(startChatLabel, !isAiModeChatGpt); SetComponentVisibility(startChatButton, !isAiModeChatGpt); diff --git a/code/sdk/application/wearable/fd230app/nativeui/applist/include/ApplistView.h b/code/sdk/application/wearable/fd230app/nativeui/applist/include/ApplistView.h index 8d2e58323..e957f265a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/applist/include/ApplistView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/applist/include/ApplistView.h @@ -161,8 +161,9 @@ private: void CircleListStyleOnStop(void); UIViewGroup * CircleListGroup_{nullptr}; UIImageView * CircleListAPP[12]{nullptr}; - UIImageView * CircleListImage1{nullptr}; - UIImageView * CircleListImage2{nullptr}; + // UIImageView * CircleListImage1{nullptr}; + // UIImageView * CircleListImage2{nullptr}; + UIImageView * PointImage{nullptr}; UIImageView * CircleListSelectImage{nullptr}; UIPicker * CircleListPicker{nullptr}; int CircleListAPPNum{0}; 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 22f951d1f..783764575 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistView.cpp @@ -88,15 +88,20 @@ ApplistView::~ApplistView() delete CircleListGroup_; CircleListGroup_ = nullptr; } - if(CircleListImage1) + // if(CircleListImage1) + // { + // delete CircleListImage1; + // CircleListImage1 = nullptr; + // } + // if(CircleListImage2) + // { + // delete CircleListImage2; + // CircleListImage2 = nullptr; + // } + if(PointImage) { - delete CircleListImage1; - CircleListImage1 = nullptr; - } - if(CircleListImage2) - { - delete CircleListImage2; - CircleListImage2 = nullptr; + delete PointImage; + PointImage = nullptr; } if(CircleListSelectImage) { @@ -372,27 +377,92 @@ 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 const int CIRCLE_CENTER_X = 233; +static const int CIRCLE_CENTER_Y = 233; +static const int CIRCLE_RADIUS = 233; +static OHOS::Point curpoint; +static OHOS::Point prepoint; + +// 计算两点之间的距离 +static double calculateDistance(const OHOS::Point& p1, const OHOS::Point& p2) +{ + return std::sqrt(std::pow(p2.x - p1.x, 2) + std::pow(p2.y - p1.y, 2)); +} +// 将触摸点坐标转换为相对于圆心的坐标 +static OHOS::Point convertToRelativeCoordinates(const OHOS::Point& point) +{ + OHOS::Point relativePoint; + relativePoint.x = point.x - CIRCLE_CENTER_X; + relativePoint.y = point.y - CIRCLE_CENTER_Y; + return relativePoint; +} +// 使用 atan2 函数计算点与水平正方向的夹角(弧度制) +static double calculateAngle(const OHOS::Point& point) +{ + double angle = std::atan2(point.y, point.x); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "x:%d,y:%d",point.x,point.y); + return angle; +} //获取是否是正向旋转 -static bool isDirectRotate(const DragEvent& event) +static void isDirectRotate(const DragEvent& event,bool &isDirectRotate) { - int startpointX = event.GetStartPoint().x; - int startpointY = event.GetStartPoint().y; - bool isDirectRotate = false; - uint8_t dragDirection = event.GetDragDirection(); - if ((dragDirection == DragEvent::DIRECTION_TOP_TO_BOTTOM && startpointX >= 233) || - (dragDirection == DragEvent::DIRECTION_BOTTOM_TO_TOP && startpointX < 233) || - (dragDirection == DragEvent::DIRECTION_LEFT_TO_RIGHT && startpointY < 233) || - (dragDirection == DragEvent::DIRECTION_RIGHT_TO_LEFT && startpointY >= 233)) + // 计算当前点与水平正方向的夹角(弧度制) + double angle_cur = calculateAngle(curpoint); + // 计算上一次点与水平正方向的夹角(弧度制) + double angle_pre = calculateAngle(prepoint); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "angle_cur:%lf,angle_pre:%lf",angle_cur,angle_pre); + + // 判断滑动方向,通过比较角度差值 + bool isDirectRotateTemp = isDirectRotate; + double angleDiff = angle_cur - angle_pre; + if (angleDiff >= 0) { isDirectRotate = true; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "顺时针滑动"); + } + else + { + isDirectRotate = false; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "逆时针滑动"); + } + if((angle_cur < 0 && angle_pre > 0) || (angle_cur > 0 && angle_pre < 0)) + { + isDirectRotate = isDirectRotateTemp; + if(isDirectRotateTemp) + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "逆时针滑动->顺时针滑动"); + else + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "顺时针滑动->逆时针滑动"); } - return isDirectRotate; } +// 计算当前缩放比例 +// startangle: 起始角度 +// isClockwiseRotation: 是否顺时针旋转 +static int calculateCurscale(int startangle, bool isClockwiseRotation ) +{ + int curscale = 0; + if (startangle!= 0 && startangle % 30 == 0) { + curscale = 30; + } else { + int baseMod = startangle % 30; + if (startangle > 0) { + curscale =!isClockwiseRotation ? 30 - baseMod : baseMod; + } else if (startangle < 0) { + curscale = isClockwiseRotation ? 30 + baseMod : baseMod; + } else { + curscale =!isClockwiseRotation ? 30 - baseMod : 30 + baseMod; + } + } + + return curscale; +} static void native_app_position_init(UIImageView ** CircleListAPP,int CircleListAPPNum,int startangle,uint8_t array[]) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "startangle:%d",startangle); - +#if 0 double curangle = startangle; double curscale = (int)curangle % NATIVE_APP_ANGEL_INTERVAL; int x = 0; @@ -490,31 +560,426 @@ static void native_app_position_init(UIImageView ** CircleListAPP,int CircleList curangle += NATIVE_APP_ANGEL_INTERVAL; } RootView::GetInstance()->Invalidate(); +#endif + double curangle = startangle;// 当前角度 + int xPos = 0; + int yPos = 0; + int size = 81; + int margin = 100 - size;//边距 + int R = CIRCLE_WATCH_R - size / 2 - margin; + + if(startangle % 30 == 0) + { + int index = 0; + int appIndex = 0; + int circleIndex = 0; + + int nativeAppNum = ApplistModel::GetInstance().GetAppListNum(); + int native_app_image_start_index = 0; + + if(startangle > 0 ) + { + int numToChange = startangle / 30; + for (int i = 1; i <= numToChange; i++) + { + // 计算 index 和 appIndex + index = i % nativeAppNum + 11; + appIndex = index; + if (startangle >= 360) { + appIndex = index % nativeAppNum; + } + + // 计算 circleIndex + circleIndex = (12 - i) % 12; + if (circleIndex < 0) { + circleIndex += 12; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "circleIndex:%d,appIndex:%d name:%s", circleIndex, appIndex, ApplistModel::GetInstance().GetApplistItems()[appIndex].iconSmall); + CircleListAPP[circleIndex]->SetSrc(ApplistModel::GetInstance().GetApplistItems()[appIndex].iconSmall); + CircleListAPP[circleIndex]->SetViewIndex(ApplistModel::GetInstance().GetApplistItems()[appIndex].id); + } + + } + else if(startangle < 0) + { + int numToChange = abs(startangle) / 30; + for (int i = 1; i <= numToChange; i++) + { + index = i % nativeAppNum + 11; + appIndex = index; + if (abs(startangle) >= 360) + { + appIndex = index % nativeAppNum; + } + circleIndex = ((abs(startangle) - 30) / 30 ) % 12; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "circleIndex:%d,appIndex:%d name:%s", circleIndex, appIndex, ApplistModel::GetInstance().GetApplistItems()[appIndex].iconSmall); + CircleListAPP[circleIndex]->SetSrc(ApplistModel::GetInstance().GetApplistItems()[appIndex].iconSmall); + CircleListAPP[circleIndex]->SetViewIndex(ApplistModel::GetInstance().GetApplistItems()[appIndex].id); + } + } + else + { + for(int i = 0;i < CircleListAPPNum;i++) + { + index = i % 2; // 使用取模操作实现循环列表 + if(index == 0) + { + array[i] = 0; + } + else + { + array[i] = 1; + } + } + } + } + + //更改图片位置和大小 + for(int i = 0; i < CircleListAPPNum; i++) + { + xPos = ((CIRCLE_WATCH_R - cos(curangle*PI_OVER_180) * R) - size / 2); + yPos = ((CIRCLE_WATCH_R - sin(curangle*PI_OVER_180) * R) - size / 2); + CircleListAPP[i]->SetPosition(xPos, yPos, size,size); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "xPos:%d,yPos:%d",xPos,yPos); + curangle += NATIVE_APP_ANGEL_INTERVAL ; //每个NATIVE_APP位置变化NATIVE_APP_ANGEL_INTERVAL度 + } + RootView::GetInstance()->Invalidate(); +} + +// 根据起始角度、旋转方向以及相关索引更新CircleListAPP和选中图片信息(顺时针且直接旋转情况) +static void updateCircleListAndSelectImageForDirectClockwise(UIImageView** CircleListAPP, + UIImageView* CircleListSelectImage_, + int startangle, + int& curselectImageIndex, + int& preselectImageIndex, + int nativeAppNum) +{ + int nextstartangle = startangle + (30 - angleIncrement); + if (nextstartangle % 30 == 0) { + int tempIndex = (nextstartangle / 30); + // 计算 index 和 appIndex + int index = tempIndex % nativeAppNum + 11; + int appIndex = index; + if (nextstartangle >= 360) { + appIndex = index % nativeAppNum; + } + + // 计算 circleIndex + int circleIndex = (12 - tempIndex) % 12; + if (circleIndex < 0) { + circleIndex += 12; + } + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "circleIndex:%d,appIndex:%d name:%s", circleIndex, appIndex, ApplistModel::GetInstance().GetApplistItems()[appIndex].iconSmall); + CircleListAPP[circleIndex]->SetSrc(ApplistModel::GetInstance().GetApplistItems()[appIndex].iconSmall); + CircleListAPP[circleIndex]->SetViewIndex(ApplistModel::GetInstance().GetApplistItems()[appIndex].id); + + // 选中图片计算 + if (nextstartangle <= 180) { + if (preselectImageIndex == 0 && curselectImageIndex == 12) { + preselectImageIndex = 1; + curselectImageIndex = 0; + } else { + preselectImageIndex = curselectImageIndex; + curselectImageIndex = (curselectImageIndex - 1) % nativeAppNum; + } + } else { + if (preselectImageIndex == 1 && curselectImageIndex == 0) { + preselectImageIndex = 0; + curselectImageIndex = 12; + } else { + preselectImageIndex = curselectImageIndex; + curselectImageIndex = (curselectImageIndex + 1) % nativeAppNum; + } + } + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[curselectImageIndex,preselectImageIndex]:[%d,%d]", curselectImageIndex, preselectImageIndex); + CircleListSelectImage_->SetSrc(ApplistModel::GetInstance().GetApplistItems()[curselectImageIndex].iconLarge); + CircleListSelectImage_->SetViewIndex(ApplistModel::GetInstance().GetApplistItems()[curselectImageIndex].id); + ApplistModel::GetInstance().SetCurselectImageIndex(curselectImageIndex); + ApplistModel::GetInstance().SetPreselectImageIndex(preselectImageIndex); + } +} + +// 根据起始角度、旋转方向以及相关索引更新CircleListAPP(顺时针且非直接旋转情况) +static void updateCircleListForClockwiseNotDirect(UIImageView** CircleListAPP, + UIImageView* CircleListSelectImage_, + int startangle, + int& curselectImageIndex, + int& preselectImageIndex, + int nativeAppNum) +{ + int prevStartAngle = startangle + angleIncrement; + if (prevStartAngle % 30 == 0) + { + int appIndex = (12 - (prevStartAngle) / 30) % nativeAppNum; + int circleIndex = appIndex % 12; + if (circleIndex < 0) { + circleIndex += 12; + } + if (appIndex < 0) { + appIndex = (- appIndex + 11) % nativeAppNum; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "circleIndex:%d,appIndex:%d name:%s", circleIndex, appIndex, ApplistModel::GetInstance().GetApplistItems()[appIndex].iconSmall); + CircleListAPP[circleIndex]->SetSrc(ApplistModel::GetInstance().GetApplistItems()[appIndex].iconSmall); + CircleListAPP[circleIndex]->SetViewIndex(ApplistModel::GetInstance().GetApplistItems()[appIndex].id); + } + + if(startangle % 30 == 0) + { + // 选中图片计算 + if(startangle <= 180) + { + if(preselectImageIndex == 0 && curselectImageIndex == 12) + { + preselectImageIndex = 1; + curselectImageIndex = 0; + } + else + { + curselectImageIndex = preselectImageIndex; + preselectImageIndex = curselectImageIndex + 1 % nativeAppNum; + } + } + else + { + if(preselectImageIndex == 12 && curselectImageIndex == 13) + { + preselectImageIndex = 0; + curselectImageIndex = 12; + } + else + { + curselectImageIndex = (curselectImageIndex - 1 + nativeAppNum) % nativeAppNum; + preselectImageIndex = (preselectImageIndex - 1 + nativeAppNum) % nativeAppNum; + } + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[curselectImageIndex->preselectImageIndex]:[%d->%d]", curselectImageIndex,preselectImageIndex); + CircleListSelectImage_->SetSrc(ApplistModel::GetInstance().GetApplistItems()[curselectImageIndex].iconLarge); + CircleListSelectImage_->SetViewIndex(ApplistModel::GetInstance().GetApplistItems()[curselectImageIndex].id); + ApplistModel::GetInstance().SetCurselectImageIndex(curselectImageIndex); + ApplistModel::GetInstance().SetPreselectImageIndex(preselectImageIndex); + } +} + +// 根据起始角度、旋转方向以及相关索引更新CircleListAPP和选中图片信息(逆时针且非直接旋转情况) +static void updateCircleListAndSelectImageForCounterclockwiseNotDirect(UIImageView** CircleListAPP, + UIImageView* CircleListSelectImage_, + int startangle, + int& curselectImageIndex, + int& preselectImageIndex, + int nativeAppNum) +{ + int absStartAngle = abs(startangle - (30 - angleIncrement)); + if (absStartAngle % 30 == 0) { + int index = (absStartAngle / 30) % nativeAppNum + 11; + int appIndex = index; + if (absStartAngle >= 360) { + appIndex = index % nativeAppNum; + } + int circleIndex = ((absStartAngle - 30) / 30 ) % 12; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "circleIndex:%d,appIndex:%d name:%s", circleIndex, appIndex, ApplistModel::GetInstance().GetApplistItems()[appIndex].iconSmall); + CircleListAPP[circleIndex]->SetSrc(ApplistModel::GetInstance().GetApplistItems()[appIndex].iconSmall); + CircleListAPP[circleIndex]->SetViewIndex(ApplistModel::GetInstance().GetApplistItems()[appIndex].id); + + preselectImageIndex = curselectImageIndex; + curselectImageIndex = (curselectImageIndex + 1) % nativeAppNum; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[curselectImageIndex->preselectImageIndex]:[%d->%d]", curselectImageIndex, preselectImageIndex); + CircleListSelectImage_->SetSrc(ApplistModel::GetInstance().GetApplistItems()[curselectImageIndex].iconLarge); + CircleListSelectImage_->SetViewIndex(ApplistModel::GetInstance().GetApplistItems()[curselectImageIndex].id); + ApplistModel::GetInstance().SetCurselectImageIndex(curselectImageIndex); + ApplistModel::GetInstance().SetPreselectImageIndex(preselectImageIndex); + } } + +// 根据起始角度、旋转方向以及相关索引更新CircleListAPP和选中图片信息(逆时针且直接旋转情况) +static void updateCircleListAndSelectImageForCounterclockwiseDirect(UIImageView** CircleListAPP, + UIImageView* CircleListSelectImage_, + int startangle, + int& curselectImageIndex, + int& preselectImageIndex, + int nativeAppNum) +{ + int absStartAngle = abs(startangle); + if (absStartAngle % 30 == 0) { + int appIndex = (absStartAngle / 30) % nativeAppNum ; + int circleIndex = (absStartAngle / 30) % 12; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "circleIndex:%d,appIndex:%d name:%s", circleIndex, appIndex, ApplistModel::GetInstance().GetApplistItems()[appIndex].iconSmall); + CircleListAPP[circleIndex]->SetSrc(ApplistModel::GetInstance().GetApplistItems()[appIndex].iconSmall); + CircleListAPP[circleIndex]->SetViewIndex(ApplistModel::GetInstance().GetApplistItems()[appIndex].id); + + curselectImageIndex = preselectImageIndex; + preselectImageIndex = (preselectImageIndex - 1 + nativeAppNum) % nativeAppNum; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[curselectImageIndex->preselectImageIndex]:[%d->%d]", curselectImageIndex, preselectImageIndex); + CircleListSelectImage_->SetSrc(ApplistModel::GetInstance().GetApplistItems()[curselectImageIndex].iconLarge); + CircleListSelectImage_->SetViewIndex(ApplistModel::GetInstance().GetApplistItems()[curselectImageIndex].id); + ApplistModel::GetInstance().SetCurselectImageIndex(curselectImageIndex); + ApplistModel::GetInstance().SetPreselectImageIndex(preselectImageIndex); + } +} + +// 根据起始角度为0的情况更新CircleListAPP和选中图片信息 +static void updateCircleListAndSelectImageWhenStartangleZero(UIImageView** CircleListAPP, + UIImageView* CircleListSelectImage_, + int& curselectImageIndex, + int& preselectImageIndex, + bool isDirectRotate) +{ + int index = 0; + int appIndex = 0; + int circleIndex = 0; + if (!isDirectRotate) { + index = 0; + appIndex = 11; + circleIndex = 11; + } else { + index = 0; + appIndex = 0; + circleIndex = 0; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "circleIndex:%d,appIndex:%d name:%s", circleIndex, appIndex, ApplistModel::GetInstance().GetApplistItems()[appIndex].iconSmall); + CircleListAPP[circleIndex]->SetSrc(ApplistModel::GetInstance().GetApplistItems()[appIndex].iconSmall); + + curselectImageIndex = preselectImageIndex; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[curselectImageIndex->preselectImageIndex]:[%d->%d]", curselectImageIndex, preselectImageIndex); + CircleListSelectImage_->SetSrc(ApplistModel::GetInstance().GetApplistItems()[curselectImageIndex].iconLarge); + CircleListSelectImage_->SetViewIndex(ApplistModel::GetInstance().GetApplistItems()[curselectImageIndex].id); + ApplistModel::GetInstance().SetCurselectImageIndex(curselectImageIndex); + ApplistModel::GetInstance().SetPreselectImageIndex(preselectImageIndex); +} + +static void fillArray(int CircleListAPPNum, int curscale) { + curscale = abs(curscale); + bool isEvenPattern = (curscale >= 0 && curscale % 60 == 0) || (curscale < 0 && curscale % 60 == -60); + bool isOddPattern = (curscale >= 0 && curscale % 60 == 30) || (curscale < 0 && curscale % 60 == -30); + + for (int i = 0; i < CircleListAPPNum; ++i) { + if (isEvenPattern && i % 2 == 0) { + array[i] = 0; + } else if (isEvenPattern && i % 2!= 0) { + array[i] = 1; + } else if (isOddPattern && i % 2 == 0) { + array[i] = 1; + } else if (isOddPattern && i % 2!= 0) { + array[i] = 0; + } + } +} + +//更改图片位置和大小的函数 +static void updateImagePositionAndSize(UIImageView** CircleListAPP, int CircleListAPPNum, int startangle, int curscale) +{ +#if 0 + double curangle = startangle;// 当前角度 + int xPos = 0; + int yPos = 0; + int size = native_small_app_size + abs(curscale*0.6); + int size2 = native_big_app_size - abs(curscale*0.6); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "curscale:%d",curscale); + int margin1 = 100 - size;//边距 + int margin2 = 100 - size2;//边距 + int R = CIRCLE_WATCH_R - size / 2 - margin1; + int R2 = CIRCLE_WATCH_R - size2 / 2 - margin2; + //更改图片位置和大小 + for(int i = 0; i < CircleListAPPNum; i++) + { + if(array[i] == 0) + { + xPos = ((CIRCLE_WATCH_R - cos(curangle*PI_OVER_180) * R) - size / 2); + yPos = ((CIRCLE_WATCH_R - sin(curangle*PI_OVER_180) * R) - size / 2); + CircleListAPP[i]->SetPosition(xPos, yPos, size,size); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "size:%d",size); + } + else + { + xPos = ((CIRCLE_WATCH_R - cos(curangle*PI_OVER_180) * R2) - size2 / 2); + yPos = ((CIRCLE_WATCH_R - sin(curangle*PI_OVER_180) * R2) - size2 / 2); + CircleListAPP[i]->SetPosition(xPos, yPos, size2,size2); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "size2:%d",size2); + } + curangle += NATIVE_APP_ANGEL_INTERVAL ; //每个NATIVE_APP位置变化NATIVE_APP_ANGEL_INTERVAL度 + } + if(startangle % 30 == 0) + fillArray(CircleListAPPNum,startangle); +#endif + /* -------------------------------------------------------------------------- */ + double curangle = startangle;// 当前角度 + int xPos = 0; + int yPos = 0; + int size = 81; + int margin = 100 - size;//边距 + int R = CIRCLE_WATCH_R - size / 2 - margin; + + //更改图片位置和大小 + for(int i = 0; i < CircleListAPPNum; i++) + { + xPos = ((CIRCLE_WATCH_R - cos(curangle*PI_OVER_180) * R) - size / 2); + yPos = ((CIRCLE_WATCH_R - sin(curangle*PI_OVER_180) * R) - size / 2); + CircleListAPP[i]->SetPosition(xPos, yPos, size,size); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "xPos:%d,yPos:%d",xPos,yPos); + curangle += NATIVE_APP_ANGEL_INTERVAL ; //每个NATIVE_APP位置变化NATIVE_APP_ANGEL_INTERVAL度 + } + /* -------------------------------------------------------------------------- */ +} + static void native_app_position_update(UIImageView ** CircleListAPP,int CircleListAPPNum,UIImageView *CircleListSelectImage_,int startangle,bool isDirectRotate) { // 打印起始角度 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "startangle:%d",startangle); + double curangle = startangle;// 当前角度 + int curscale = 0; + // int curscale = calculateCurscale(startangle, isDirectRotate);// 缩放系数 + int nativeAppNum = ApplistModel::GetInstance().GetAppListNum(); + int curselectImageIndex = ApplistModel::GetInstance().GetCurselectImageIndex(); //当前选中图片索引 + int preselectImageIndex = ApplistModel::GetInstance().GetPreselectImageIndex(); //上一次选中图片索引 - // 当前角度 - double curangle = startangle; - // 缩放系数 - int curscale = 0; + if (startangle % 30 == 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "startangle:%d,[curselectImageIndex,preselectImageIndex]:[%d,%d]", startangle, curselectImageIndex, preselectImageIndex); + native_app_position_update_startflag = 0; //表示可以下次更新了 + ApplistModel::GetInstance().SetCircleListStartAngle(startangle); + } - // 计算缩放系数 - if (startangle!= 0 && startangle % 30 == 0) { - curscale = 30; - } else { - int baseMod = startangle % 30; - if (startangle > 0) { - curscale =!isDirectRotate? 30 - baseMod : baseMod; - } else if (startangle < 0) { - curscale = isDirectRotate? 30 + baseMod : baseMod; - } else { - curscale =!isDirectRotate? 30 - baseMod : 30 + baseMod; + if (startangle > 0) + { + //顺时针 + if (isDirectRotate) + { + updateCircleListAndSelectImageForDirectClockwise(CircleListAPP,CircleListSelectImage_,startangle,curselectImageIndex,preselectImageIndex,nativeAppNum); + } + else//逆时针处理 + { + updateCircleListForClockwiseNotDirect(CircleListAPP,CircleListSelectImage_,startangle,curselectImageIndex,preselectImageIndex,nativeAppNum); } } + else if(startangle < 0) + { + if (!isDirectRotate) //逆时针 + { + updateCircleListAndSelectImageForCounterclockwiseNotDirect(CircleListAPP,CircleListSelectImage_,startangle,curselectImageIndex,preselectImageIndex,nativeAppNum); + } + else + { + updateCircleListAndSelectImageForCounterclockwiseDirect(CircleListAPP,CircleListSelectImage_,startangle,curselectImageIndex,preselectImageIndex,nativeAppNum); + } + } + else + { + updateCircleListAndSelectImageWhenStartangleZero(CircleListAPP,CircleListSelectImage_,curselectImageIndex,preselectImageIndex,isDirectRotate); + } + + updateImagePositionAndSize(CircleListAPP, CircleListAPPNum, startangle, curscale); + RootView::GetInstance()->Invalidate(); + return; + + #if 0 + // 打印起始角度 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "startangle:%d",startangle); + + // 当前角度 + double curangle = startangle; + // 缩放系数 + int curscale = calculateCurscale(startangle, isDirectRotate); int nativeAppNum = ApplistModel::GetInstance().GetAppListNum(); @@ -607,7 +1072,7 @@ static void native_app_position_update(UIImageView ** CircleListAPP,int CircleLi } else //逆时针处理 { - int prevStartAngle = startangle + 3; + int prevStartAngle = startangle + angleIncrement; if(prevStartAngle % 30 == 0) { appIndex = (12 - (prevStartAngle) / 30) % nativeAppNum; @@ -638,7 +1103,7 @@ static void native_app_position_update(UIImageView ** CircleListAPP,int CircleLi else { curselectImageIndex = preselectImageIndex; - preselectImageIndex = curselectImageIndex + 1; + preselectImageIndex = curselectImageIndex + 1 % nativeAppNum; } } else @@ -666,7 +1131,7 @@ static void native_app_position_update(UIImageView ** CircleListAPP,int CircleLi { if(!isDirectRotate) //逆时针 { - int absStartAngle = abs(startangle - (30 - 3)); + int absStartAngle = abs(startangle - (30 - angleIncrement)); if(absStartAngle % 30 == 0) { index = (absStartAngle / 30) % nativeAppNum + 11; @@ -761,6 +1226,7 @@ static void native_app_position_update(UIImageView ** CircleListAPP,int CircleLi // 刷新视图 RootView::GetInstance()->Invalidate(); + #endif /* -------------------------------------------------------------------------- */ } class AppCircleListOnDragListener : public UIView::OnDragListener, @@ -780,19 +1246,32 @@ public: bool OnDragStart(UIView& view, const DragEvent& event) override { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AppCircleListOnDragListener::OnDragStart"); + prepoint = convertToRelativeCoordinates(event.GetStartPoint()); + preX = event.GetStartPoint().x; + preY = event.GetStartPoint().y; return true; } bool OnDrag(UIView& view, const DragEvent& event) override { - int deltaX = abs(event.GetLastPoint().x - event.GetStartPoint().x); - int deltaY = abs(event.GetLastPoint().y - event.GetStartPoint().y); - if (deltaX < 50 && deltaY < 50) + int curX = event.GetCurrentPos().x; + int curY = event.GetCurrentPos().y; + int deltaX = abs(curX - preX); + int deltaY = abs(curY - preY); + if (deltaX < 8 && deltaY < 8) { return false; } - - + curpoint = convertToRelativeCoordinates(event.GetCurrentPos()); + /* -------------------------------------------------------------------------- */ + isDirectRotate(event,isDirectRotateFlag); + angle += (isDirectRotateFlag ? angleIncrement : - angleIncrement); + native_app_position_update(CircleListAPP,CircleListAPPNum,CircleListSelectImage,angle,isDirectRotateFlag); + /* -------------------------------------------------------------------------- */ + prepoint = curpoint; + preX = curX; + preY = curY; + /* -------------------------------------------------------------------------- */ return true; } @@ -800,16 +1279,27 @@ public: bool OnDragEnd(UIView& view, const DragEvent& event) override { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AppCircleListOnDragListener::OnDragEnd"); +#if 0 if(native_app_position_update_startflag == 0) { native_app_position_update_startflag = 1; OnDragEndFlag = 1; isDirectRotateFlag = isDirectRotate(event);//获取是否是正向旋转的标志 } +#endif + if(angle % 30 == 0) //不需要补偿角度 + { + OnDragEndFlag = 0; + } + else + { + OnDragEndFlag = 1; + } return true; } void Notify() override { +#if 0 if(OnDragEndFlag) { int angleIncrement = isDirectRotateFlag? 3 : -3; @@ -824,44 +1314,86 @@ public: if(native_app_position_update_startflag) native_app_position_update(CircleListAPP,CircleListAPPNum,CircleListSelectImage,angle,isDirectRotateFlag); } +#else + if(OnDragEndFlag) + { + if(angle % 30 == 0) //不需要补偿角度 + { + OnDragEndFlag = 0; + } + else + { + if(angle > 0) + { + if(isDirectRotateFlag) + { + angle += angleIncrement; + } + else + { + angle -= angleIncrement; + } + } + else + { + if(isDirectRotateFlag) + { + angle += angleIncrement; + } + else + { + angle -= angleIncrement; + } + } + native_app_position_update(CircleListAPP,CircleListAPPNum,CircleListSelectImage,angle,isDirectRotateFlag); + } + } + return; +#endif } - void OnPickerStoped(UIPicker &picker) override + + bool OnRotate(UIView& view, const RotateEvent& event) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "preOnSelectPickerIndex:%d,picker.GetSelected:%d",preOnSelectPickerIndex,picker.GetSelected()); - // 判断是否为逆时针方向 - if ((preOnSelectPickerIndex == 0 && picker.GetSelected() == 1) || - (preOnSelectPickerIndex == 1 && picker.GetSelected() == 2) || - (preOnSelectPickerIndex == 2 && picker.GetSelected() == 0)) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AppCircleListOnDragListener::OnRotate %d",event.GetRotate()); + 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); } - // 判断是否为顺时针方向 - else if ((preOnSelectPickerIndex == 1 && picker.GetSelected() == 0) || - (preOnSelectPickerIndex == 0 && picker.GetSelected() == 2) || - (preOnSelectPickerIndex == 2 && picker.GetSelected() == 1)) { - isDirectRotateFlag = true; + + 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; } - - if (preOnSelectPickerIndex!= picker.GetSelected()) + else { - if (native_app_position_update_startflag == 0) - { - native_app_position_update_startflag = 1; - OnDragEndFlag = 1; - } - // 更新之前选中的索引值为当前选中的值 - preOnSelectPickerIndex = picker.GetSelected(); + OnDragEndFlag = 1; } - return; + return false; } + private: - UIImageView **CircleListAPP{nullptr}; - UIImageView *CircleListSelectImage{nullptr}; - int CircleListAPPNum{0}; - int angle = 0; //要旋转角度 - int rotateangle{0}; //旋转累计角度 - uint8_t OnDragEndFlag{0};//是否拖拽结束的标志 - bool isDirectRotateFlag{false};//是否是正向旋转的标志 - int preOnSelectPickerIndex{1};//当前picker选中索引 + UIImageView **CircleListAPP{nullptr}; //图片组件数组 + UIImageView *CircleListSelectImage{nullptr}; //中间选中图片的图片组件 + int CircleListAPPNum{0}; //图片组件数量 + int angle = 0; //要旋转角度 + int rotateangle{0}; //旋转累计角度 + uint8_t OnDragEndFlag{0}; //是否拖拽结束的标志 + bool isDirectRotateFlag{false}; //是否是正向旋转的标志 + int preX{0}; + int preY{0}; }; void ApplistView::CircleListStyleOnStart(void) @@ -895,7 +1427,7 @@ void ApplistView::CircleListStyleOnStart(void) CircleListPicker->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); CircleListPicker->SetStyle(STYLE_BACKGROUND_OPA, 0x00); CircleListPicker->SetStyle(STYLE_BORDER_RADIUS, 150); - CircleListPicker->SetItemHeight(60); + CircleListPicker->SetItemHeight(30); CircleListPicker->SetLoopState(true); CircleListPicker->SetRotateFactor(1.0); CircleListPicker->RequestFocus(); @@ -909,18 +1441,18 @@ void ApplistView::CircleListStyleOnStart(void) CircleListGroup_->Add(CircleListPicker); } /* -------------------------------------------------------------------------- */ - if(CircleListImage1 == nullptr) - { - CircleListImage1 = new UIImageView(); - if(nullptr == CircleListImage1) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ApplistView::CircleListImage1 failed!! [%d]", __LINE__); - return; - } - CircleListImage1->SetPosition(114, 122, 220, 330); - CircleListImage1->SetSrc("/user/res/themestyle/circlelist/circleListImage1.bin"); - CircleListGroup_->Add(CircleListImage1); - } + // if(CircleListImage1 == nullptr) + // { + // CircleListImage1 = new UIImageView(); + // if(nullptr == CircleListImage1) + // { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ApplistView::CircleListImage1 failed!! [%d]", __LINE__); + // return; + // } + // CircleListImage1->SetPosition(120, 122, 220, 330); + // CircleListImage1->SetSrc("/user/res/themestyle/circlelist/circleListImage1.bin"); + // CircleListGroup_->Add(CircleListImage1); + // } /* -------------------------------------------------------------------------- */ CircleListAPPNum = sizeof(CircleListAPP) / sizeof(CircleListAPP[0]);//图片显示数量 /* -------------------------------------------------------------------------- */ @@ -953,21 +1485,43 @@ void ApplistView::CircleListStyleOnStart(void) } native_app_position_init(CircleListAPP,CircleListAPPNum,ApplistModel::GetInstance().GetCircleListStartAngle() ,array); /* -------------------------------------------------------------------------- */ - if(CircleListImage2 == nullptr) + // if(CircleListImage2 == nullptr) + // { + // CircleListImage2 = new UIImageView(); + // if(nullptr == CircleListImage2) + // { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ApplistView::CircleListImage2 failed!! [%d]", __LINE__); + // return; + // } + // int x = CircleListAPP[0]->GetX(); + // int y = CircleListAPP[0]->GetY(); + // int w = CircleListAPP[0]->GetWidth(); + // int h = CircleListAPP[0]->GetHeight(); + // CircleListImage2->SetAutoEnable(false); + // CircleListImage2->SetResizeMode(UIImageView::FILL); + // CircleListImage2->SetPosition(x, y, w, h); + // CircleListImage2->SetSrc("/user/res/themestyle/circlelist/circleListImage2.bin"); + // CircleListImage2->SetTouchable(true); + // CircleListImage2->SetOnClickListener(presenter_); + // CircleListImage2->SetViewIndex(VIEW_INVALID); + // CircleListGroup_->Add(CircleListImage2); + // } + /* -------------------------------------------------------------------------- */ + if(nullptr == PointImage) { - CircleListImage2 = new UIImageView(); - if(nullptr == CircleListImage2) + PointImage = new UIImageView(); + if(nullptr == PointImage) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ApplistView::CircleListImage2 failed!! [%d]", __LINE__); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ApplistView::PointImage failed!! [%d]", __LINE__); return; } - CircleListImage2->SetPosition(28, 197, 72, 72); - CircleListImage2->SetSrc("/user/res/themestyle/circlelist/circleListImage2.bin"); - CircleListImage2->SetTouchable(true); - CircleListImage2->SetOnClickListener(presenter_); - CircleListImage2->SetViewIndex(VIEW_INVALID); - CircleListGroup_->Add(CircleListImage2); + PointImage->SetPosition(330, 233, 10, 10); + PointImage->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + PointImage->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + PointImage->SetStyle(STYLE_BORDER_RADIUS, 200); + CircleListGroup_->Add(PointImage); } + /* -------------------------------------------------------------------------- */ if(CircleListSelectImage == nullptr) { CircleListSelectImage = new UIImageView(); @@ -976,7 +1530,7 @@ void ApplistView::CircleListStyleOnStart(void) WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ApplistView::CircleListSelectImage failed!! [%d]", __LINE__); return; } - CircleListSelectImage->SetPosition(CircleListImage1->GetX() + 30, CircleListImage1->GetY() + 30,160,160); + CircleListSelectImage->SetPosition(153, 153,160,160); CircleListSelectImage->SetAutoEnable(false); CircleListSelectImage->SetResizeMode(UIImageView::SCALE_DOWN); CircleListSelectImage->SetSrc(ApplistModel::GetInstance().GetApplistItems()[ApplistModel::GetInstance().GetCurselectImageIndex()].iconLarge); @@ -996,7 +1550,7 @@ void ApplistView::CircleListStyleOnStart(void) } } CircleListGroup_->SetOnDragListener(static_cast(AppCircleListOnDragListener_)); - CircleListPicker->RegisterSelectedListener(static_cast(AppCircleListOnDragListener_)); + CircleListPicker->SetOnRotateListener(static_cast(AppCircleListOnDragListener_)); /* -------------------------------------------------------------------------- */ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::CircleListStyleOnStart success!! [%d]", __LINE__); } -- 2.17.1