From: Caisking <3449750381@qq.com> Date: Thu, 9 May 2024 10:25:45 +0000 (+0800) Subject: 优化多国语言变量字符串更新 X-Git-Tag: release_V1.2.70_20241020_135402~1025^2~8^2^2~7 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=472be5ff4b3f2da2a20ac08a06c3d292a25eb646;p=mirrors%2FFD230.git 优化多国语言变量字符串更新 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenView.cpp b/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenView.cpp index c6bced889..6ee4c6ed9 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenView.cpp @@ -100,7 +100,7 @@ namespace OHOS } else if (time_diff <= 60) { - UpdateLabel(timeLabel, time_diff); + UpdateLabel(timeLabel, time_diff,STR_CHECKNO); } else { 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 fac88ccca..989263e4e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartView.cpp @@ -102,7 +102,7 @@ namespace OHOS } else if (time_diff <= 60) { - UpdateLabel(timeLabel, time_diff); + UpdateLabel(timeLabel, time_diff,STR_CHECKNO); } else { diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardPresenter.cpp index 30e224263..86394b3e2 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardPresenter.cpp @@ -374,7 +374,7 @@ namespace OHOS /*训练暂停*/ void TraingCardPresenter::handlePauseState() { - TrainingControlView::GetInstance()->GetLabel()->SetText("ç»§ç»­"); + TrainingControlView::GetInstance()->GetLabel()->SetTextId(STR_RESUME); TrainingControlView::GetInstance()->GetButton()->SetImageSrc(SPORT_CONTINUE_IMAGE, SPORT_CONTINUE_IMAGE); TraingModel::GetInstance()->SetSportState(ExerciseState::Pause); PauseTimer(); @@ -384,7 +384,7 @@ namespace OHOS /*训练继续*/ void TraingCardPresenter::handleContinueState() { - TrainingControlView::GetInstance()->GetLabel()->SetText("暂停"); + TrainingControlView::GetInstance()->GetLabel()->SetTextId(STR_PAUSE); TrainingControlView::GetInstance()->GetButton()->SetImageSrc(SPORT_PAUSE_IMAGE, SPORT_PAUSE_IMAGE); TraingModel::GetInstance()->SetSportState(ExerciseState::Continue); ResumeTimer(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/uicomponents/UIComponents.cpp b/code/sdk/application/wearable/fd230app/nativeui/uicomponents/UIComponents.cpp index c46d58655..453879a0e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/uicomponents/UIComponents.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/uicomponents/UIComponents.cpp @@ -242,7 +242,7 @@ namespace OHOS imageAnimator->SetPosition(left, top); imageAnimator->Resize(width, height); imageAnimator->SetViewId(viewId); - imageAnimator->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + // imageAnimator->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); imageAnimator->SetStyle(STYLE_BACKGROUND_OPA, 0xff); ImageAnimatorInfo *imageAnimatorInfo = new ImageAnimatorInfo[numFrames]; @@ -258,9 +258,9 @@ namespace OHOS imageAnimator->SetImageAnimatorSrc(imageAnimatorInfo, numFrames, time); // 200 is the default delay time imageAnimator->SetTimeOfPause(time); - imageAnimator->SetRepeatTimes(1); - imageAnimator->SetReverse(true); - // imageAnimator->SetVisible(true); + imageAnimator->SetRepeat(true); + // imageAnimator->SetReverse(true); + // imageAnimator->SetVisible(true); } /*带默认参数的初始化label*/ void InitLabelDefault(UILabelExt *&label, int x, int y, int width, int height, const char *viewId, const char *text, int fontSize, const char *fontName) @@ -269,44 +269,60 @@ namespace OHOS } /*替换字符串中的变量*/ - void UpdateLabelText(UILabelExt *&label, const std::string &newText) + std::string UpdateLabelText(UILabelExt *&label, const std::string &newText, UIResourceTextId id) { if (label == nullptr) { - return; + return nullptr; } + /*取Id对应的字符串*/ + UILabelExt *labelext = new UILabelExt(); + labelext->SetTextId(id); + std::string text = labelext->GetText(); - std::string str = label->GetText(); - printf("UpdateLabel:%s->%s\r\n", str.c_str(), newText.c_str()); + printf("UpdateLabel:%s->%s\r\n", text.c_str(), newText.c_str()); // 找到标志"XX"在字符串中的位置 - size_t pos = str.find("XX"); + size_t pos = text.find("XX"); if (pos != std::string::npos) { // 替换标志"XX"为更新字符串 - str.replace(pos, 2, newText); // 2 是标志"XX"的长度 - label->SetText(str.c_str()); + text.replace(pos, 2, newText); // 2 是标志"XX"的长度 + printf("newText:%s\r\n", text.c_str()); + label->SetText(text.c_str()); + } + else + { + printf("找不到变量标志位XX,请注意是否已经被修改!\r\n"); } + + delete labelext; + return text; } /*更新数字*/ - void UpdateLabel(UILabelExt *&label, int num) + std::string UpdateLabel(UILabelExt *&label, int num, UIResourceTextId id) { + if (label == nullptr) { - return; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "label is error"); + return nullptr; } - UpdateLabelText(label, std::to_string(num)); + std::string str = UpdateLabelText(label, std::to_string(num), id); + return str; } /*更新文本*/ - void UpdateLabel(UILabelExt *&label, const std::string &updateStr) + std::string UpdateLabel(UILabelExt *&label, const std::string &updateStr, UIResourceTextId id) { if (label == nullptr) { - return; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "label is error"); + return nullptr; } - UpdateLabelText(label, updateStr); + std::string str = UpdateLabelText(label, updateStr, id); + return str; } /*设置label的Id*/ @@ -332,4 +348,3 @@ namespace OHOS } -/*更新label的字符串*/ diff --git a/code/sdk/application/wearable/fd230app/nativeui/uicomponents/UIComponents.h b/code/sdk/application/wearable/fd230app/nativeui/uicomponents/UIComponents.h index 88027cfb5..ba19be1e7 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/uicomponents/UIComponents.h +++ b/code/sdk/application/wearable/fd230app/nativeui/uicomponents/UIComponents.h @@ -53,11 +53,11 @@ namespace OHOS 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); /*通用替换*/ - void UpdateLabelText(UILabelExt *&label, const std::string &newText); + std::string UpdateLabelText(UILabelExt *&label, const std::string &newText, UIResourceTextId id); /*更新label的数字*/ - void UpdateLabel(UILabelExt *&label, int num); + std::string UpdateLabel(UILabelExt *&label, int num, UIResourceTextId id); /*更新label的字符串*/ - void UpdateLabel(UILabelExt *&label, const std::string &updatestr); + std::string UpdateLabel(UILabelExt *&label, const std::string &updatestr, UIResourceTextId id); /*通过labelext获取Id设置label*/ void SetLabelId(UILabel *&label, UIResourceTextId id); }