From fae0533d6005fe2daebaa3e27d393303d8d37152 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Sun, 29 Sep 2024 20:18:42 +0800 Subject: [PATCH] =?utf8?q?=E6=8C=87=E5=8D=97=E9=92=88=E7=95=8C=E9=9D=A2?= =?utf8?q?=E5=A4=9A=E5=9B=BD=E8=AF=AD=E8=A8=80=E7=BF=BB=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../compass/include/CompassPresenter.h | 10 +++--- .../nativeui/compass/include/CompassView.h | 5 +-- .../nativeui/compass/src/CompassPresenter.cpp | 32 +++++++++++++------ .../nativeui/compass/src/CompassView.cpp | 18 +++++++++-- 4 files changed, 46 insertions(+), 19 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/compass/include/CompassPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/compass/include/CompassPresenter.h index cd8770c78..c7d820c9b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/compass/include/CompassPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/compass/include/CompassPresenter.h @@ -1,8 +1,9 @@ /* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: CompassPresenter.h - * Author: - * Create: 2021-12-21 + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-08-05 15:20:01 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-09-29 20:01:58 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/compass/include/CompassPresenter.h */ #ifndef COMPASS_PRESENTER_H #define COMPASS_PRESENTER_H @@ -22,6 +23,7 @@ typedef struct { uint16_t beginAngle; uint16_t endAngle; const char *dir; + int dir_textId;//方向的textid } CompassItem; class CompassView; diff --git a/code/sdk/application/wearable/fd230app/nativeui/compass/include/CompassView.h b/code/sdk/application/wearable/fd230app/nativeui/compass/include/CompassView.h index 420dee6ee..9fb75c0fb 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/compass/include/CompassView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/compass/include/CompassView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-12 11:44:04 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-23 15:18:13 + * @LastEditTime: 2024-09-29 19:48:52 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/compass/include/CompassView.h */ @@ -28,6 +28,7 @@ public: ~CompassView() override; void DirectionSetText(const char *text, const char *angle); + void DirectionSetTextId(int textId, const char *angle); static CompassView *GetInstance(void); void CompassStartRotate(int16_t numb); bool InitPage(void); @@ -42,7 +43,7 @@ public: private: bool LoadCompassImage(UIImageView *view, uint32_t resId); void ClearAll(void); - UILabel *directionLabel{nullptr}; //方向标签 + UILabelExt *directionLabel{nullptr}; //方向标签 UILabel *angledLabel{nullptr}; //角度标签 UIImageView *backGround{nullptr}; //背景图片 UIImageView *PlaceMarkerImage{nullptr}; //放置标记图片 diff --git a/code/sdk/application/wearable/fd230app/nativeui/compass/src/CompassPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/compass/src/CompassPresenter.cpp index 454ae7615..9b8c4b87d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/compass/src/CompassPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/compass/src/CompassPresenter.cpp @@ -9,6 +9,7 @@ #include "compass/include/CompassModel.h" #include "graphic_service.h" #include "gfx_utils/mem_check.h" +#include "ui_resource_string.h" namespace OHOS { static constexpr int16_t RIGHT_NORTH_DOWN_23 = 23; static constexpr int16_t RIGHT_EASTNORTH_UP_68 = 68; @@ -43,14 +44,23 @@ static constexpr const char *WESTSOUTH_DIRECTION = (char *)"西南"; static constexpr const char *EASTSOUTH_DIRECTION = (char *)"东南"; static constexpr const char *EASTNORTH_DIRECTION = (char *)"东北"; +static constexpr const int NORTH_DIRECTION_TEXTID = STR_NORTH;//北 +static constexpr const int SOUTH_DIRECTION_TEXTID = STR_SOUTH;//南 +static constexpr const int WEST_DIRECTION_TEXTID = STR_WEST;//西 +static constexpr const int EAST_DIRECTION_TEXTID = STR_EAST;//东 +static constexpr const int WESTNORTH_DIRECTION_TEXTID = STR_NORTHWEST;//西北 +static constexpr const int WESTSOUTH_DIRECTION_TEXTID = STR_SOUTHWEST;//西南 +static constexpr const int EASTSOUTH_DIRECTION_TEXTID = STR_SOUTHEAST;//西南 +static constexpr const int EASTNORTH_DIRECTION_TEXTID = STR_NORTHEAST;//东北 + const CompassItem g_compassList[] = { - {RIGHT_NORTH_DOWN_23, RIGHT_EASTNORTH_UP_68, EASTNORTH_DIRECTION}, - {RIGHT_EASTNORTH_UP_68, RIGHT_EAST_UP_113, EAST_DIRECTION}, - {RIGHT_EAST_UP_113, RIGHT_EASTSOUTH_UP_158, EASTSOUTH_DIRECTION}, - {RIGHT_EASTSOUTH_UP_158, RIGHT_SOUTH_UP_203, SOUTH_DIRECTION}, - {RIGHT_SOUTH_UP_203, RIGHT_WESTSOUTH_UP_248, WESTSOUTH_DIRECTION}, - {RIGHT_WESTSOUTH_UP_248, RIGHT_WEST_UP_293, WEST_DIRECTION}, - {RIGHT_WEST_UP_293, RIGHT_WESTNORTH_UP_338, WESTNORTH_DIRECTION} + {RIGHT_NORTH_DOWN_23, RIGHT_EASTNORTH_UP_68, EASTNORTH_DIRECTION,EASTNORTH_DIRECTION_TEXTID}, + {RIGHT_EASTNORTH_UP_68, RIGHT_EAST_UP_113, EAST_DIRECTION,EAST_DIRECTION_TEXTID}, + {RIGHT_EAST_UP_113, RIGHT_EASTSOUTH_UP_158, EASTSOUTH_DIRECTION,EASTSOUTH_DIRECTION_TEXTID}, + {RIGHT_EASTSOUTH_UP_158, RIGHT_SOUTH_UP_203, SOUTH_DIRECTION,SOUTH_DIRECTION_TEXTID}, + {RIGHT_SOUTH_UP_203, RIGHT_WESTSOUTH_UP_248, WESTSOUTH_DIRECTION,WESTSOUTH_DIRECTION_TEXTID}, + {RIGHT_WESTSOUTH_UP_248, RIGHT_WEST_UP_293, WEST_DIRECTION,WEST_DIRECTION_TEXTID}, + {RIGHT_WEST_UP_293, RIGHT_WESTNORTH_UP_338, WESTNORTH_DIRECTION,WESTNORTH_DIRECTION_TEXTID} }; static CompassPresenter *g_pMainView = nullptr; @@ -85,12 +95,14 @@ void CompassPresenter::DisplayAngleRight(uint16_t angle) { if ((angle >= RIGHT_WESTNORTH_UP_338) || (angle >= 0 && angle < RIGHT_NORTH_DOWN_23)) { //CompassView::GetInstance()->DirectionSetText(NORTH_DIRECTION, ("~" + std::to_string(angle) + "°").c_str()); - CompassView::GetInstance()->DirectionSetText(NORTH_DIRECTION, (std::to_string(angle) + "°").c_str()); + // CompassView::GetInstance()->DirectionSetText(NORTH_DIRECTION, (std::to_string(angle) + "°").c_str()); + CompassView::GetInstance()->DirectionSetTextId(NORTH_DIRECTION_TEXTID, (std::to_string(angle) + "°").c_str()); } for (int i = 0; i < DIRECTION_COUNT; i++) { if ((angle >= g_compassList[i].beginAngle) && (angle < g_compassList[i].endAngle)) { - CompassView::GetInstance()->DirectionSetText(g_compassList[i].dir, ("~" + std::to_string(angle) + "°").c_str()); - CompassView::GetInstance()->DirectionSetText(g_compassList[i].dir, (std::to_string(angle) + "°").c_str()); + // CompassView::GetInstance()->DirectionSetText(g_compassList[i].dir, ("~" + std::to_string(angle) + "°").c_str()); + // CompassView::GetInstance()->DirectionSetText(g_compassList[i].dir, (std::to_string(angle) + "°").c_str()); + CompassView::GetInstance()->DirectionSetTextId(g_compassList[i].dir_textId, (std::to_string(angle) + "°").c_str()); } } } diff --git a/code/sdk/application/wearable/fd230app/nativeui/compass/src/CompassView.cpp b/code/sdk/application/wearable/fd230app/nativeui/compass/src/CompassView.cpp index b28c82704..1eeeb5634 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/compass/src/CompassView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/compass/src/CompassView.cpp @@ -10,6 +10,7 @@ #include "compass/include/CompassView.h" #include "compass/include/MainCompassView.h" #include "compass/include/CompassPresenter.h" +#include "ui_resource_string.h" namespace OHOS { static constexpr int16_t COMPASSVIEW_W = 466; static constexpr int16_t COMPASSVIEW_H = 466; @@ -83,6 +84,17 @@ void CompassView::DirectionSetText(const char *text, const char *angle) directionLabel->SetText(text); angledLabel->SetText(angle); } +void CompassView::DirectionSetTextId(int textId, const char *angle) +{ + if(directionLabel && angledLabel) + { + directionLabel->SetTextId(textId); + directionLabel->Invalidate(); + + angledLabel->SetText(angle); + angledLabel->Invalidate(); + } +} //加载指南针图片 bool CompassView::LoadCompassImage(UIImageView *view, uint32_t resId) { @@ -190,7 +202,7 @@ bool CompassView::InitPage(void) return false; } - directionLabel = new UILabel(); + directionLabel = new UILabelExt(); if (directionLabel == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "directionLabel new fail"); ClearAll(); @@ -198,7 +210,7 @@ bool CompassView::InitPage(void) } directionLabel->SetPosition(DIRECTIONLABEL_X, DIRECTIONLABEL_Y); directionLabel->Resize(DIRECTIONLABEL_TEXT_WIDTH, DIRECTIONLABEL_TEXT_HEIGH); - directionLabel->SetText("北"); + directionLabel->SetTextId(STR_NORTH); directionLabel->SetStyle(STYLE_TEXT_FONT, DIRECTIONLABEL_FONT_TEXT_SIZE); directionLabel->SetStyle(STYLE_LINE_HEIGHT, DIRECTIONLABEL_STYLE_LINE_HEIGHT); directionLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, DIRECTIONLABEL_FONT_TEXT_SIZE); @@ -220,7 +232,7 @@ bool CompassView::InitPage(void) angledLabel->SetText("0°"); angledLabel->SetStyle(STYLE_TEXT_FONT, ANGLEDLABEL_FONT_TEXT_SIZE); angledLabel->SetStyle(STYLE_LINE_HEIGHT, ANGLEDLABEL_STYLE_LINE_HEIGHT); - angledLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, ANGLEDLABEL_FONT_TEXT_SIZE); + angledLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, ANGLEDLABEL_FONT_TEXT_SIZE); angledLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); angledLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); angledLabel->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); -- 2.17.1