指南针界面多国语言翻译
authorluozheng <1732036298@qq.com>
Sun, 29 Sep 2024 12:18:42 +0000 (20:18 +0800)
committerluozheng <1732036298@qq.com>
Sun, 29 Sep 2024 12:18:42 +0000 (20:18 +0800)
code/sdk/application/wearable/fd230app/nativeui/compass/include/CompassPresenter.h
code/sdk/application/wearable/fd230app/nativeui/compass/include/CompassView.h
code/sdk/application/wearable/fd230app/nativeui/compass/src/CompassPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/compass/src/CompassView.cpp

index cd8770c..c7d820c 100644 (file)
@@ -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;
index 420dee6..9fb75c0 100644 (file)
@@ -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};                         //放置标记图片
index 454ae76..9b8c4b8 100644 (file)
@@ -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());
         }
     }
 }
index b28c827..1eeeb56 100644 (file)
@@ -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);