多国语言支持变量适配(updateLabel)
authorCaisking <3449750381@qq.com>
Tue, 7 May 2024 09:27:40 +0000 (17:27 +0800)
committerCaisking <3449750381@qq.com>
Tue, 7 May 2024 09:27:40 +0000 (17:27 +0800)
code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartBandoffView.h
code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartView.cpp
code/sdk/application/wearable/fd230app/nativeui/uicomponents/UIComponents.cpp
code/sdk/application/wearable/fd230app/nativeui/uicomponents/UIComponents.h

index 5b78cce..192cca7 100644 (file)
@@ -1,3 +1,9 @@
+/*** 
+ * @Date: 2024-04-15 10:55:58
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-05-07 17:00:01
+ * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartBandoffView.h
+ */
 /*** 
  * @Date: 2024-04-15 10:55:58
  * @LastEditors: Caisking 3449750381@qq.com
index 198d342..0c54815 100644 (file)
@@ -14,6 +14,7 @@
 #include "heartrate/include/HeartCheckView.h"
 #include "heartrate/include/HeartRateView.h"
 #include "language/font/ui_resource_string.h"
+#include "uicomponents/UIComponents.h"
 
 namespace OHOS
 {
@@ -92,7 +93,9 @@ namespace OHOS
             uint64_t time = HeartPresenter::GetInstance()->GetCurrentTime();
             uint64_t check_time = HeartModel::GetInstance()->GetCheckTime();
             TimeStr = HeartPresenter::GetInstance()->GetTDOA(time, check_time) + "检测";
-            timeLabel->SetText(TimeStr.c_str());
+            // timeLabel->SetText(TimeStr.c_str());
+            timeLabel->SetTextId(STR_CHECKTIME);
+            UpdateLabel(timeLabel, TimeStr);
         }
         else
         {
@@ -165,7 +168,9 @@ namespace OHOS
             uint64_t time = HeartPresenter::GetInstance()->GetCurrentTime();
             uint64_t check_time = HeartModel::GetInstance()->GetCheckTime();
             TimeStr = HeartPresenter::GetInstance()->GetTDOA(time, check_time) + "检测";
-            timeLabel->SetText(TimeStr.c_str());
+            // timeLabel->SetText(TimeStr.c_str());
+            timeLabel->SetTextId(STR_CHECKTIME);
+            UpdateLabel(timeLabel, TimeStr);
         }
         else
         {
index 7f817d4..87c9fd1 100644 (file)
@@ -267,4 +267,38 @@ namespace OHOS
     {
         InitLabel(label, x, y, width, height, viewId, text, fontName, fontSize);
     }
+
+    /*更新label的数字*/
+    void UpdateLabel(UILabelExt *&label, int num)
+    {
+        std::string str = label->GetText();
+        std::string numStr = std::to_string(num);
+        printf("UpdateLabel:%s->%d\r\n", str.c_str(), num);
+
+        // 找到标志"XX"在字符串中的位置
+        size_t pos = str.find("XX");
+        if (pos != std::string::npos)
+        {
+            // 替换标志"XX"为数字字符串
+            str.replace(pos, 2, numStr); // 2 是标志"XX"的长度
+        }
+
+        label->SetText(str.c_str());
+    }
+
+    /*更新label的字符串*/
+    void UpdateLabel(UILabelExt *&label, const std::string updatestr)
+    {
+        std::string str = label->GetText();
+        printf("UpdateLabel:%s->%s\r\n", str.c_str(), updatestr.c_str());
+        // 找到标志"XX"在字符串中的位置
+        size_t pos = str.find("XX");
+        if (pos != std::string::npos)
+        {
+            // 替换标志"XX"为数字字符串
+            str.replace(pos, 2, updatestr); // 2 是标志"XX"的长度
+        }
+
+        label->SetText(str.c_str());
+    }
 }
\ No newline at end of file
index 1b5d04f..7b0164a 100644 (file)
@@ -1,3 +1,9 @@
+/***
+ * @Date: 2024-04-25 10:56:15
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-05-06 18:24:03
+ * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/uicomponents/UIComponents.h
+ */
 /***
  * @Date: 2024-04-23 16:04:31
  * @LastEditors: Caisking 3449750381@qq.com
@@ -46,5 +52,10 @@ namespace OHOS
     /*InitLabel[默认参数]*/
     void InitLabelDefault(UILabelExt *&label, int x, int y, int width, int height, const char *viewId, const char *text, int fontSize = 30, const char *fontName = DEFAULT_VECTOR_FONT_FILENAME);
 
+    /*更新label的数字*/
+    void UpdateLabel(UILabelExt *&label, int num);
+    /*更新label的字符串*/
+    void UpdateLabel(UILabelExt *&label, const std::string updatestr);
+
 }
 #endif // UICOMPONENTS_H
\ No newline at end of file