From: Caisking <3449750381@qq.com> Date: Tue, 7 May 2024 09:27:40 +0000 (+0800) Subject: 多国语言支持变量适配(updateLabel) X-Git-Tag: release_V1.2.70_20241020_135402~1025^2~29 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=37cb0389985733d03f45037bdac14be2fe28a056;p=mirrors%2FFD230.git 多国语言支持变量适配(updateLabel) --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartBandoffView.h b/code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartBandoffView.h index 5b78ccecb..192cca73e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartBandoffView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartBandoffView.h @@ -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 diff --git a/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartView.cpp b/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartView.cpp index 198d342e8..0c5481591 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartView.cpp @@ -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 { diff --git a/code/sdk/application/wearable/fd230app/nativeui/uicomponents/UIComponents.cpp b/code/sdk/application/wearable/fd230app/nativeui/uicomponents/UIComponents.cpp index 7f817d4d4..87c9fd1ed 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/uicomponents/UIComponents.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/uicomponents/UIComponents.cpp @@ -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 diff --git a/code/sdk/application/wearable/fd230app/nativeui/uicomponents/UIComponents.h b/code/sdk/application/wearable/fd230app/nativeui/uicomponents/UIComponents.h index 1b5d04f5c..7b0164af3 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/uicomponents/UIComponents.h +++ b/code/sdk/application/wearable/fd230app/nativeui/uicomponents/UIComponents.h @@ -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