From: Caisking <3449750381@qq.com> Date: Thu, 1 Feb 2024 08:57:46 +0000 (+0800) Subject: 增加多国语言功能,在系统语言界面可以测试 X-Git-Tag: release_V1.2.70_20241020_135402~1316 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=07129a22ec1bf59fc505e5fc8131765ba3440b66;p=mirrors%2FFD230.git 增加多国语言功能,在系统语言界面可以测试 --- diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index d709cfd9d..f179865ac 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -54,6 +54,7 @@ set(PRIVATE_HEADER ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/include ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/src/ui/frameworks ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/include/service + ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/innerkits ${ROOT_DIR}/middleware/services/gui/lvgl/src/hal diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index 77a6b5ec7..8b46b34a8 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -61,7 +61,6 @@ #include "dial/include/DialView.h" #include "blood/include/BloodCardView.h" - #include "weather/include/MainWeatherPresenter.h" #include "weather/include/MainWeatherView.h" #include "weather/include/WeatherReportPresenter.h" @@ -105,6 +104,9 @@ #include "graphic_hardware_config.h" #include "graphic_service.h" #include "common/graphic_startup.h" +#include "font/ui_font.h" +#include "font/font_global_manager.h" + namespace OHOS { @@ -148,7 +150,7 @@ namespace OHOS {VIEW_SCREEN_DURATION, &NativeLauncher::InitScreenDurationSlice}, // 亮屏时长实例化地址 {VIEW_SECONDARY_FUNCTION, &NativeLauncher::InitSecondaryFunction}, - {VIEW_QUICK_ACCESS,&NativeLauncher::InitQuickAccessSlice}, //快速访问实例化地址 + {VIEW_QUICK_ACCESS, &NativeLauncher::InitQuickAccessSlice}, // 快速访问实例化地址 {VIEW_FAST_TRAINING, &NativeLauncher::InitFastTrainingSlice}, {VIEW_FAST_TRAINING_ATTENTION, &NativeLauncher::InitFastTrainingAttentionSlice}, @@ -188,8 +190,16 @@ namespace OHOS void NativeLauncher::InitNativeLauncher() { + //初始化语言 GraphicStartUp::InitFontEngine(MEM_POOL_UI_FONT, MEM_POOL_UI_FONT_SIZE, OHOS::VECTOR_FONT_DIR, DEFAULT_VECTOR_FONT_FILENAME); WEARABLE_LOGI(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "NativeLauncher::InitNativeLauncher"); + /* -------------------------------------------------------------------------- */ + //注册中文和英语两种语言包 + static const char *BIN_LANG_EN = RES_PATH "font/en.lang"; + static const char *BIN_LANG_ZH = RES_PATH "font/zh.lang"; + const char *resFiles[] = {BIN_LANG_ZH, BIN_LANG_EN}; + FontGlobalManager::GetInstance()->RegisterLanguageInfo(resFiles, (sizeof(resFiles) / sizeof(char *)), 1); + /* -------------------------------------------------------------------------- */ // 初始化所有预加载slice InitBtHeadsetEvent(); // 蓝牙ct和tg适配初始化 InitAllNativeSlices(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/language/UILabelButtonExt_Init.cpp b/code/sdk/application/wearable/fd230app/nativeui/language/UILabelButtonExt_Init.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/code/sdk/application/wearable/fd230app/nativeui/language/UILabelButtonExt_Init.h b/code/sdk/application/wearable/fd230app/nativeui/language/UILabelButtonExt_Init.h new file mode 100644 index 000000000..f5e2c74bb --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/language/UILabelButtonExt_Init.h @@ -0,0 +1,10 @@ +/*** + * @Author: Caisking 3449750381@qq.com + * @Date: 2024-02-01 14:09:40 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-02-01 14:09:43 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/language/UILabelButtonExt_Init.h + * @Description: + * @ + * @Copyright (c) 2024 by Caisking , All Rights Reserved. + */ diff --git a/code/sdk/application/wearable/fd230app/nativeui/language/UILabelExt_Init.cpp b/code/sdk/application/wearable/fd230app/nativeui/language/UILabelExt_Init.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/code/sdk/application/wearable/fd230app/nativeui/language/UILabelExt_Init.h b/code/sdk/application/wearable/fd230app/nativeui/language/UILabelExt_Init.h new file mode 100644 index 000000000..b35be8119 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/language/UILabelExt_Init.h @@ -0,0 +1,10 @@ +/*** + * @Author: Caisking 3449750381@qq.com + * @Date: 2024-02-01 14:09:58 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-02-01 14:10:01 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/language/UILabelExt_Init.h + * @Description: + * @ + * @Copyright (c) 2024 by Caisking , All Rights Reserved. + */ diff --git a/code/sdk/application/wearable/fd230app/nativeui/language/config/README b/code/sdk/application/wearable/fd230app/nativeui/language/config/README new file mode 100644 index 000000000..89d2a5587 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/language/config/README @@ -0,0 +1,64 @@ +## 根元素 + +XML 必须以 language 为根元素并支持以下属性, + +language 元素中的属性对所有的子元素都生效,并且作为子元素的默认值, + +如果子元素有定义相同的属性,以子元素设置的生效。 + + + +**表3-3 多语言 xml 配置** + +| 属性名 | 描述 | 取值 | 必选 | +| ------------ | ------------------------------------------------------------ | :---------------------------------------------- | :--: | +| languageinfo | 语言信息,使用语言代码 (ISO 639)标识语言 | ISO 639 标准定义的语言代码 | Y | +| direct | 文本方向布局 | ltr(left to right) rtl (right to left) | N | +| fontName | 设置矢量字库名,路径需要 在 graphic_config.h 中配置 宏 VECTOR_FONT_DIR。 | ttf 文件名 | N | + +例如: + +```c++ + + + +``` + + + +## 字符串元素 + +字符串元素以 lanstr 为命名,定义字符串的相关信息,包括字符串取值、文本大小、 字库名等信息。 + +如果根元素也定义的相同的属性,会以字符串元素中定义的值为准, + + 如果都没有定义,取 UIKit 中设置的默认值。 + + + + **表3-4 字符串元素配置** + +| 属性名 | 描述 | 取值 | 必选 | +| -------- | ------------------------------------------------------------ | ----------------------------------------------- | ---- | +| id | 字符串唯一标识,需要保证唯一性 | 统一以 STR_ 为前缀 是 value 字符串内容 | Y | +| value | 字符串内容 | 任意字符串 | Y | +| direct | 文本方向布局 | ltr(left to right) rtl (right to left) | N | +| size | 文本大小,如果同时有在代码中通 过接口 SetFont 进行设置,会按照 和 SetText 以及 ForceResetText 先 后顺序为准 | 0~255 | N | +| fontName | 设置矢量字库名,路径需要在 graphic_config.h 中配置宏 VECTOR_FONT_DIR。如果同时有 在代码中通过接口 SetFont 进行设 置,会按照和 SetText 以及 ForceResetText 先后顺序为准 | ttf 文件名 | N | + +例如: + +```c++ + +``` + diff --git a/code/sdk/application/wearable/fd230app/nativeui/language/config/font/en.lang b/code/sdk/application/wearable/fd230app/nativeui/language/config/font/en.lang new file mode 100644 index 000000000..a58e4c0b5 Binary files /dev/null and b/code/sdk/application/wearable/fd230app/nativeui/language/config/font/en.lang differ diff --git a/code/sdk/application/wearable/fd230app/nativeui/language/config/font/ui_resource_string.h b/code/sdk/application/wearable/fd230app/nativeui/language/config/font/ui_resource_string.h new file mode 100644 index 000000000..309da6b0f --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/language/config/font/ui_resource_string.h @@ -0,0 +1,41 @@ +/* +* Copyright (c) xxxxxxxx Technologies Co., Ltd. 2021-2021. All rights reserved. +* Description: language +* Author: Graphic develop team +* Create: 2021-07-06 +*/ + +#ifndef UI_RESOURCE_STRING_H +#define UI_RESOURCE_STRING_H +#include +namespace OHOS { +enum UIResourceTextId : uint16_t { + STR_IMAGE = 0, + STR_PROGRESSBAR = 1, + STR_SLIDEUNLOCK = 2, + STR_LISTBOX = 3, + STR_BUTTON = 4, + STR_SCROLLVIEW = 5, + STR_SCROLLGRID = 6, + STR_CLOCK = 7, + STR_DISTURBANCE = 8, + STR_BRIGHT = 9, + STR_PHONE = 10, + STR_LANGAGE = 11, + STR_ALARM = 12, + STR_SYSTEM = 13, + STR_SPO2 = 14, + STR_COMPASS = 15, + STR_INDOORWALK = 16, + STR_WEATHER = 17, + STR_SYSTEMSETTING = 18, + STR_MAX_ID = 19, +}; // UIResourceTextId + +enum FontLanguageId : uint8_t { + LANGUAGE_ID_ZH, + LANGUAGE_ID_EN, + LANGUAGE_ID_MAX +}; // UITextLanguageTextId +} +#endif /* UI_RESOURCE_STRING_H */ diff --git a/code/sdk/application/wearable/fd230app/nativeui/language/config/font/zh.lang b/code/sdk/application/wearable/fd230app/nativeui/language/config/font/zh.lang new file mode 100644 index 000000000..de8ffb0fa Binary files /dev/null and b/code/sdk/application/wearable/fd230app/nativeui/language/config/font/zh.lang differ diff --git a/code/sdk/application/wearable/fd230app/nativeui/language/config/language_en.xml b/code/sdk/application/wearable/fd230app/nativeui/language/config/language_en.xml new file mode 100644 index 000000000..7d4baae84 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/language/config/language_en.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/language/config/language_zh.xml b/code/sdk/application/wearable/fd230app/nativeui/language/config/language_zh.xml new file mode 100644 index 000000000..14e03d60f --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/language/config/language_zh.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLanguageView.h b/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLanguageView.h index 294bb2bb3..a84c792f1 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLanguageView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLanguageView.h @@ -7,6 +7,7 @@ #include "components/ui_label.h" #include "components/ui_radio_button.h" #include "components/ui_image_view.h" +#include "components/ui_label_ext.h" namespace OHOS { class SystemLanguageView @@ -54,7 +55,7 @@ namespace OHOS void SetRadioButtonSelectStatus(UIRadioButton &radiobutton, bool state); // 设置单选框的选择状态 private: UIScrollView *scrollView = nullptr; - UILabel *Title = nullptr; // 标题 + UILabelExt *Title = nullptr; // 标题 UIImageView *Background[2]{nullptr}; // 放组件的背景 UILabel *SimplifiedChineseLabel = nullptr; UILabel *EnglishLabel = nullptr; diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemPresenter.h index 57140a529..405828c1f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemPresenter.h @@ -1,3 +1,13 @@ +/*** + * @Author: Caisking 3449750381@qq.com + * @Date: 2024-01-29 19:58:37 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-02-01 16:27:58 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemPresenter.h + * @Description: + * @ + * @Copyright (c) 2024 by Caisking , All Rights Reserved. + */ #ifndef SYSTEM_PRESENTER_H #define SYSTEM_PRESENTER_H @@ -26,9 +36,10 @@ namespace OHOS class RadiobuttonOnChangeListener : public UICheckBox::OnChangeListener { public: - RadiobuttonOnChangeListener(UIRadioButton *uiView) + RadiobuttonOnChangeListener(UIRadioButton *uiView, UILabelExt *label) { m_uiView = uiView; + m_label = label; } ~RadiobuttonOnChangeListener() {} bool isChineseRadioButtonSelected(); @@ -37,6 +48,7 @@ namespace OHOS private: UIRadioButton *m_uiView{nullptr}; + UILabelExt *m_label{nullptr}; }; class SystemViewOnDragListener : public UIView::OnDragListener diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemLanguageView.cpp b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemLanguageView.cpp index 9ae0227e9..3f460502a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemLanguageView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemLanguageView.cpp @@ -131,19 +131,15 @@ namespace OHOS } scrollView->SetOnDragListener(draglistener); /* ---------------------------------- Title --------------------------------- */ - Title = new UILabel(); + Title = new UILabelExt(); if (Title == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemLanguageView::Title new fail!"); return nullptr; } - Title->SetPosition(203, 52); - Title->SetStyle(STYLE_TEXT_FONT, 30); - Title->SetStyle(STYLE_LINE_HEIGHT, 35); - Title->SetText("语言"); - Title->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - Title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + Title->SetPosition(203, 52, 200, 35); + Title->SetTextId(11); + //Title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); scrollView->Add(Title); /* ------------------------------- Background ------------------------------- */ ImageConfig imageconfig = { @@ -214,7 +210,7 @@ namespace OHOS return nullptr; } SetRadioButtonSelectStatus(*SimplifiedChineseRadioButton, true); - UICheckBox::OnChangeListener* SimplifiedChineseRadioButtonChange = static_cast(new RadiobuttonOnChangeListener(SimplifiedChineseRadioButton)); + UICheckBox::OnChangeListener *SimplifiedChineseRadioButtonChange = static_cast(new RadiobuttonOnChangeListener(SimplifiedChineseRadioButton,Title)); SimplifiedChineseRadioButton->SetOnChangeListener(SimplifiedChineseRadioButtonChange); scrollView->Add(SimplifiedChineseRadioButton); /* --------------------------- EnglishRadioButton --------------------------- */ @@ -227,7 +223,7 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemLanguageView::EnglishRadioButton new fail!"); return nullptr; } - UICheckBox::OnChangeListener* EnglishRadioButtonChange = static_cast(new RadiobuttonOnChangeListener(EnglishRadioButton)); + UICheckBox::OnChangeListener *EnglishRadioButtonChange = static_cast(new RadiobuttonOnChangeListener(EnglishRadioButton,Title)); EnglishRadioButton->SetOnChangeListener(EnglishRadioButtonChange); scrollView->Add(EnglishRadioButton); initViewStatus = true; diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemPresenter.cpp index 27d1d3542..86b02719c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemPresenter.cpp @@ -3,6 +3,9 @@ #include "graphic_math.h" #include "string.h" #include "system/include/SystemPresenter.h" +#include "font/font_global_manager.h" +#include "font/ui_font.h" + namespace OHOS { @@ -132,6 +135,7 @@ namespace OHOS { return true; } + RootView::GetInstance()->Invalidate(); return false; } @@ -147,24 +151,45 @@ namespace OHOS return false; } + /* -------------------------------------------------------------------------- */ + // 注册中文和英语两种语言包 + static const char *BIN_LANG_EN = RES_PATH "font/en.lang"; + static const char *BIN_LANG_ZH = RES_PATH "font/zh.lang"; + const char *resFiles[] = {BIN_LANG_ZH, BIN_LANG_EN}; + /* -------------------------------------------------------------------------- */ // 用来监听语言切换 bool RadiobuttonOnChangeListener::OnChange(UICheckBox::UICheckBoxState state) { + + // 获取字体单例 + UIFont *uiFont = UIFont::GetInstance(); + if (uiFont == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Get UIFont error"); + return false; + } + /* -------------------------------------------------------------------------- */ switch (state) { case UICheckBox::SELECTED: if (isChineseRadioButtonSelected()) { - // loadChineseLanguageResource();//加载中文资源 - // updateUIWithChineseText();//更新中文文本 + // 中文文本 + FontGlobalManager::GetInstance()->RegisterLanguageInfo(resFiles, (sizeof(resFiles) / sizeof(char *)), 0); + uiFont->SetCurrentLangId(0); // set language WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Switched to Chinese language"); } else if (isEnglishRadioButtonSelected()) { - // loadEnglishLanguageResource(); //加载英语资源 - // updateUIWithEnglishText(); //更新英语文本 + // 英语文本 + FontGlobalManager::GetInstance()->RegisterLanguageInfo(resFiles, (sizeof(resFiles) / sizeof(char *)), 1); + uiFont->SetCurrentLangId(1); // set language WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Switched to English language"); } + m_label->SetTextId(11); + //强制刷新 + m_label->ForceResetText(); + RootView::GetInstance()->Invalidate(); break; case UICheckBox::UNSELECTED: // Handle unselected state if needed diff --git a/code/sdk/application/wearable/nativeapp/CMakeLists.txt b/code/sdk/application/wearable/nativeapp/CMakeLists.txt index eab02415b..ad92a899a 100755 --- a/code/sdk/application/wearable/nativeapp/CMakeLists.txt +++ b/code/sdk/application/wearable/nativeapp/CMakeLists.txt @@ -52,6 +52,7 @@ set(PRIVATE_HEADER ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/include ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/src/ui/frameworks ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/src/ui/innerkits + ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/include/components ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/kits/events ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/kits diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_resource_string.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_resource_string.h new file mode 100644 index 000000000..39202f67c --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/ui_resource_string.h @@ -0,0 +1,38 @@ +/* +* Copyright (c) xxxxxxxx Technologies Co., Ltd. 2021-2021. All rights reserved. +* Description: language +* Author: Graphic develop team +* Create: 2021-07-06 +*/ + +#ifndef UI_RESOURCE_STRING_H +#define UI_RESOURCE_STRING_H +#include +namespace OHOS { +enum UIResourceTextId : uint16_t { + STR_IMAGE = 0, + STR_PROGRESSBAR = 1, + STR_SLIDEUNLOCK = 2, + STR_LISTBOX = 3, + STR_BUTTON = 4, + STR_SCROLLVIEW = 5, + STR_SCROLLGRID = 6, + STR_CLOCK = 7, + STR_22 = 8, + GLIDE_DISTURBANCE = 9, + GLIDE_BRIGHT = 10, + GLIDE_PHONE = 11, + GLIDE_ALARM = 12, + GLIDE_SYSTEM = 13, + STR_11 = 14, + GLIDE_SYSTEMSETTING = 15, + STR_MAX_ID = 16, +}; // UIResourceTextId + +enum FontLanguageId : uint8_t { + LANGUAGE_ID_ZH, + LANGUAGE_ID_EN, + LANGUAGE_ID_MAX +}; // UITextLanguageTextId +} +#endif /* UI_RESOURCE_STRING_H */ diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp index 3637aee87..c19391553 100755 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp @@ -62,12 +62,16 @@ #include "graphic_hardware_config.h" #include "graphic_service.h" #include "common/graphic_startup.h" +#include "font/font_global_manager.h" #ifdef SUPPORT_ALIPAY_SEC #include "AlipayMainView.h" #include "AlipayPresenter.h" #endif + namespace OHOS { +static const char* BIN_LANG_EN = RES_PATH"font/en.lang"; +static const char* BIN_LANG_ZH = RES_PATH"font/zh.lang"; struct AppViewMapper { AppViewId id; @@ -140,6 +144,11 @@ NativeLauncher &NativeLauncher::GetInstance(void) void NativeLauncher::InitNativeLauncher() { GraphicStartUp::InitFontEngine(MEM_POOL_UI_FONT, MEM_POOL_UI_FONT_SIZE, OHOS::VECTOR_FONT_DIR, DEFAULT_VECTOR_FONT_FILENAME); WEARABLE_LOGI(WEARABLE_LOG_MODULE_LAUNCHER_FWK, "NativeLauncher::InitNativeLauncher"); + + const char* resFiles[] = {BIN_LANG_ZH, BIN_LANG_EN}; + FontGlobalManager::GetInstance()->RegisterLanguageInfo(resFiles, (sizeof(resFiles) / sizeof(char*)), 1); + + // 初始化所有预加载slice InitBtHeadsetEvent(); // 蓝牙ct和tg适配初始化 InitAllNativeSlices(); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainViewSample.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainViewSample.cpp index 6f3503cb4..2470c12f9 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainViewSample.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainViewSample.cpp @@ -245,7 +245,7 @@ UICardPage *MainViewSample::InitWatchFacePage(void) mainClockView = new DialViewGroup(); std::string filePath = dynamic_cast(presenter_)->GetDialPath(); if (filePath.size() == 0) { - filePath = RES_PATH"dial.bin"; + filePath = RES_PATH"maomao.bin"; } mainClockView->SetDial(filePath); #else diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/PullUpDownView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/PullUpDownView.cpp index 34eb21de7..a085f3d22 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/PullUpDownView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/PullUpDownView.cpp @@ -1,3 +1,13 @@ +/*** + * @Author: Caisking 3449750381@qq.com + * @Date: 2024-01-29 19:58:37 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-02-01 14:53:13 + * @FilePath: /FD230/code/sdk/application/wearable/nativeapp/nativeui/main/src/PullUpDownView.cpp + * @Description: + * @ + * @Copyright (c) 2024 by Caisking , All Rights Reserved. + */ /* * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. * Description: WeekStep @@ -13,6 +23,8 @@ #include "ScreenModels.h" #include "SettingModel.h" #include "ui_resource_image.h" +#include "components/ui_label_ext.h" +#include "ui_resource_string.h" namespace OHOS { @@ -181,49 +193,49 @@ void PullUpDownView::InitViewImg(void) void PullUpDownView::InitViewLable(void) { - dnotDisturbLable = new UILabel(); + dnotDisturbLable = new UILabelExt(); if (dnotDisturbLable == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dnotDisturbLable new fail"); return; } dnotDisturbLable->SetPosition(DISTURB_LABEL_X, DISTURB_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); - dnotDisturbLable->SetText("勿扰"); + dnotDisturbLable->SetTextId(9); dnotDisturbLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); dnotDisturbLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); - briScreenLable = new UILabel(); + briScreenLable = new UILabelExt(); if (briScreenLable == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "briScreenLable new fail"); return; } briScreenLable->SetPosition(SCREEN_LABEL_X, SCREEN_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); - briScreenLable->SetText("亮屏"); + briScreenLable->SetTextId(10); briScreenLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); briScreenLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); - finPhoneLable = new UILabel(); + finPhoneLable = new UILabelExt(); if (finPhoneLable == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "finPhoneLable new fail"); return; } finPhoneLable->SetPosition(PHONE_LABEL_X, PHONE_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); - finPhoneLable->SetText("找手机"); + finPhoneLable->SetTextId(11); finPhoneLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); finPhoneLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); - droAlarmLable = new UILabel(); + droAlarmLable = new UILabelExt(); if (finPhoneLable == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "finPhoneLable new fail"); return; } droAlarmLable->SetPosition(ALARM_LABEL_X, ALARM_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); - droAlarmLable->SetText("闹钟"); + droAlarmLable->SetTextId(12); droAlarmLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); droAlarmLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); - droSettingLable = new UILabel(); + droSettingLable = new UILabelExt(); if (droSettingLable == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "droSettingLable new fail"); return; } droSettingLable->SetPosition(SETTING_LABEL_X, SETTING_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT); - droSettingLable->SetText("设置"); + droSettingLable->SetTextId(13); droSettingLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE); droSettingLable->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT); } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialLabelView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialLabelView.cpp index f7cb557e4..9216d6751 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialLabelView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialLabelView.cpp @@ -5,127 +5,159 @@ #include "DialLabelView.h" #include "securec.h" -namespace OHOS { -DialLabelView::DialLabelView(void) +namespace OHOS { -} - -DialLabelView::~DialLabelView(void) -{ - if (text_ != nullptr) { - UIFree(text_); + DialLabelView::DialLabelView(void) + { } -} -bool DialLabelView::SetText(const char* text) -{ - if (text == nullptr) { - return false; + DialLabelView::~DialLabelView(void) + { + if (text_ != nullptr) + { + UIFree(text_); + } } - UILabel::SetText(text); - return true; -} -void DialLabelView::SetTextWithWildcardInner(const char* text) -{ - if (strcmp(text, dstBuf_) == 0) { - return; - } - memset_s(dstBuf_, sizeof(dstBuf_), 0, sizeof(dstBuf_)); - if (strcpy_s(dstBuf_, MAX_BUF_SIZE, text) != EOK) { - GRAPHIC_LOGE("strcpy_s failed!\n"); + bool DialLabelView::SetText(const char *text) + { + if (text == nullptr) + { + return false; + } + UILabel::SetText(text); + return true; } - UILabel::SetText(dstBuf_); -} -bool DialLabelView::SetTextWithWildcard(const char* text) -{ - if (text == nullptr) { - return false; - } - if (text_ != nullptr) { - if (strcmp(text, text_) == 0) { - return true; + void DialLabelView::SetTextWithWildcardInner(const char *text) + { + if (strcmp(text, dstBuf_) == 0) + { + return; } - UIFree(text_); - text_ = nullptr; + memset_s(dstBuf_, sizeof(dstBuf_), 0, sizeof(dstBuf_)); + if (strcpy_s(dstBuf_, MAX_BUF_SIZE, text) != EOK) + { + GRAPHIC_LOGE("strcpy_s failed!\n"); + } + UILabel::SetText(dstBuf_); } - uint32_t textLen = static_cast(strlen(text)); - if (textLen > (MAX_BUF_SIZE - 1)) { - return false; - } - text_ = static_cast(UIMalloc(++textLen)); - if (text_ == nullptr) { - return false; - } - if (memcpy_s(text_, textLen, text, textLen) != EOK) { - UIFree(text_); - text_ = nullptr; - return false; + bool DialLabelView::SetTextWithWildcard(const char *text) + { + if (text == nullptr) + { + return false; + } + if (text_ != nullptr) + { + if (strcmp(text, text_) == 0) + { + return true; + } + UIFree(text_); + text_ = nullptr; + } + + uint32_t textLen = static_cast(strlen(text)); + if (textLen > (MAX_BUF_SIZE - 1)) + { + return false; + } + text_ = static_cast(UIMalloc(++textLen)); + if (text_ == nullptr) + { + return false; + } + if (memcpy_s(text_, textLen, text, textLen) != EOK) + { + UIFree(text_); + text_ = nullptr; + return false; + } + text_[textLen] = '\0'; + return true; } - text_[textLen] = '\0'; - return true; -} -void DialLabelView::HandleTextData(const std::string* data, uint16_t num) -{ - char tempBuf[MAX_BUF_SIZE] = {0}; - if (num == 1) { - if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0].c_str()) < 0) { - GRAPHIC_LOGE("snprintf_s failed.\n"); - return; + void DialLabelView::HandleTextData(const std::string *data, uint16_t num) + { + char tempBuf[MAX_BUF_SIZE] = {0}; + if (num == 1) + { + if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0].c_str()) < 0) + { + GRAPHIC_LOGE("snprintf_s failed.\n"); + return; + } } - } else if (num == 2) { // 2: wildcard cnt - if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0].c_str(), data[1].c_str()) < 0) { - GRAPHIC_LOGE("snprintf_s failed.\n"); - return; + else if (num == 2) + { // 2: wildcard cnt + if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0].c_str(), data[1].c_str()) < 0) + { + GRAPHIC_LOGE("snprintf_s failed.\n"); + return; + } } - } else if (num == 3) { // 3: wildcard cnt - if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, - data[0].c_str(), data[1].c_str(), data[2].c_str()) < 0) { // 2: index - GRAPHIC_LOGE("snprintf_s failed.\n"); + else if (num == 3) + { // 3: wildcard cnt + if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, + data[0].c_str(), "å¹´", data[1].c_str(), "月", data[2].c_str(), "日") < 0) + { // 2: index + GRAPHIC_LOGE("snprintf_s failed.\n"); + return; + } + } + else + { + GRAPHIC_LOGE("max size is 3.\n"); return; } - } else { - GRAPHIC_LOGE("max size is 3.\n"); - return; + SetTextWithWildcardInner(tempBuf); } - SetTextWithWildcardInner(tempBuf); -} -void DialLabelView::HandleFloatData(const float* data, uint16_t num) -{ - char tempBuf[MAX_BUF_SIZE] = {0}; - if (num == 1) { - if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0]) < 0) { - GRAPHIC_LOGE("snprintf_s failed.\n"); - return; + void DialLabelView::HandleFloatData(const float *data, uint16_t num) + { + char tempBuf[MAX_BUF_SIZE] = {0}; + if (num == 1) + { + if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0]) < 0) + { + GRAPHIC_LOGE("snprintf_s failed.\n"); + return; + } } - } else if (num == 2) { // 2: wildcard cnt - if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0], data[1]) < 0) { - GRAPHIC_LOGE("snprintf_s failed.\n"); - return; + else if (num == 2) + { // 2: wildcard cnt + if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0], data[1]) < 0) + { + GRAPHIC_LOGE("snprintf_s failed.\n"); + return; + } } - } else if (num == 3) { // 3: wildcard cnt - if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0], data[1], data[2]) < 0) { // 2: index - GRAPHIC_LOGE("snprintf_s failed.\n"); + else if (num == 3) + { // 3: wildcard cnt + if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0], data[1], data[2]) < 0) + { // 2: index + GRAPHIC_LOGE("snprintf_s failed.\n"); + return; + } + } + else + { + GRAPHIC_LOGE("max size is 3.\n"); return; } - } else { - GRAPHIC_LOGE("max size is 3.\n"); - return; + SetTextWithWildcardInner(tempBuf); } - SetTextWithWildcardInner(tempBuf); -} -void DialLabelView::HandleFloatData(float data) -{ - char tempBuf[MAX_BUF_SIZE] = {0}; - if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data) < 0) { - GRAPHIC_LOGE("snprintf_s failed.\n"); - return; + void DialLabelView::HandleFloatData(float data) + { + char tempBuf[MAX_BUF_SIZE] = {0}; + if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data) < 0) + { + GRAPHIC_LOGE("snprintf_s failed.\n"); + return; + } + SetTextWithWildcardInner(tempBuf); } - SetTextWithWildcardInner(tempBuf); -} } \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialModelTime.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialModelTime.cpp index 20663119b..dbc4efff6 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialModelTime.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialModelTime.cpp @@ -101,10 +101,10 @@ bool DialModelTime::GetDialFloatData(DialDataType& type, float& out) out = static_cast(angleMS_); break; case DialDataType::DATA_TYPE_TIME_YEAR: - out = static_cast(tblock_->tm_year); + out = static_cast((tblock_->tm_year) + 1900); break; case DialDataType::DATA_TYPE_TIME_MONTH: - out = static_cast(tblock_->tm_mon); + out = static_cast((tblock_->tm_mon) + 1); break; case DialDataType::DATA_TYPE_TIME_WEEK: out = static_cast(tblock_->tm_wday); diff --git a/code/sdk/build/config/target_config/brandy/config.py b/code/sdk/build/config/target_config/brandy/config.py index 3c0253820..24d0b1e42 100755 --- a/code/sdk/build/config/target_config/brandy/config.py +++ b/code/sdk/build/config/target_config/brandy/config.py @@ -147,14 +147,14 @@ target = { "audio_manager", "custom_utils", "rotary_encoder", - 'nativelauncher', - # 'fd230launcher', + # 'nativelauncher', + 'fd230launcher', "batterry_service"], 'ram_component_set': ['bgh', 'media', 'gpu', 'graphic_uikit', 'bgh_audio', 'dfx_set', 'ohos_set', 'wearable_set', 'alipay_set'], 'dsp_version': 'max', 'packet': True, - 'fs_image_path':'evb4', - # 'fs_image_path':'fd230', + # 'fs_image_path':'evb4', + 'fs_image_path':'fd230', 'fs_image': True }, #native-xts: liteos + uikit + nandflash + mipi + psram + audio 典型合封UIKIT版本 @@ -189,13 +189,13 @@ target = { "custom_utils", "rotary_encoder", # 'nativelauncher', - 'fd230launcher', + 'fd230launcher', "batterry_service"], 'ram_component_set': ['bgh', 'media', 'gpu', 'graphic_uikit', 'bgh_audio', 'dfx_set', 'ohos_set', 'wearable_set', 'xts_set', 'xts_test_set', 'alipay_set'], 'dsp_version': 'max', 'packet': True, - 'fs_image_path':'evb4', - # 'fs_image_path':'fd230', + #'fs_image_path':'evb4', + 'fs_image_path':'fd230', 'fs_image': True }, diff --git a/code/sdk/middleware/services/gui/hal/common/include/graphic_hardware_config.h b/code/sdk/middleware/services/gui/hal/common/include/graphic_hardware_config.h index 59eb8428c..8867e30c3 100755 --- a/code/sdk/middleware/services/gui/hal/common/include/graphic_hardware_config.h +++ b/code/sdk/middleware/services/gui/hal/common/include/graphic_hardware_config.h @@ -94,7 +94,7 @@ /** * @brief Whether open offline dial. */ -#define USE_OFFLINE_DIAL 0 +#define USE_OFFLINE_DIAL 1 // if ENABLE_OPENVG is set to be 1, dislpay_vau.c should be compiled. #define ENABLE_OPENVG 0 diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/include/font/font_global_manager.h b/code/sdk/middleware/services/gui/uikit/proprietary/include/font/font_global_manager.h index 535456fc3..5c8524b9a 100755 --- a/code/sdk/middleware/services/gui/uikit/proprietary/include/font/font_global_manager.h +++ b/code/sdk/middleware/services/gui/uikit/proprietary/include/font/font_global_manager.h @@ -18,7 +18,7 @@ #include #include "common/text.h" #include "components/ui_view.h" -#include "font/font_global_header.h" +#include "../src/ui/innerkits/font/font_global_header.h" #include "graphic_config.h" #include "gfx_utils/graphic_log.h" #include "gfx_utils/heap_base.h" diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_clock_dial/PullUpDownView.h b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_clock_dial/PullUpDownView.h index 4a413d15f..51c61a594 100755 --- a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_clock_dial/PullUpDownView.h +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_clock_dial/PullUpDownView.h @@ -1,3 +1,4 @@ + /* * Copyright (c) 2022 CompanyNameMagicTag. * Licensed under the Apache License, Version 2.0 (the "License"); @@ -11,6 +12,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. +#include "ui_label_ext.h" */ #ifndef PULL_UP_DOWN_VIEW_H @@ -21,6 +23,7 @@ #include "components/ui_image_view.h" #include "components/ui_label.h" #include "components/ui_label_button.h" +#include "components/ui_label_ext.h" namespace OHOS { class PullUpDownView : public AppGroupView { @@ -35,11 +38,13 @@ private: UIImageView *finPhone{nullptr}; UIImageView *droAlarm{nullptr}; UIImageView *droSetting{nullptr}; - UILabel *dnotDisturbLable{nullptr}; - UILabel *briScreenLable{nullptr}; - UILabel *finPhoneLable{nullptr}; - UILabel *droAlarmLable{nullptr}; - UILabel *droSettingLable{nullptr}; + + UILabelExt *dnotDisturbLable{nullptr}; + UILabelExt *briScreenLable{nullptr}; + UILabelExt *finPhoneLable{nullptr}; + UILabelExt *droAlarmLable{nullptr}; + UILabelExt *droSettingLable{nullptr}; + UIImageView *bluetooth{nullptr}; UIImageView *battery{nullptr}; UILabel *batteryLable{nullptr}; diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_font/res/string/language_en.xml b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_font/res/string/language_en.xml index f04195f96..5c7701b85 100755 --- a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_font/res/string/language_en.xml +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_font/res/string/language_en.xml @@ -3,53 +3,77 @@ languageinfo="en" fontName="DroidSansFallback.ttf" direct="ltf" - > +> + /> + /> + /> + /> + /> + /> + /> + /> - + /> + + + + + + + \ No newline at end of file diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_font/res/string/language_zh.xml b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_font/res/string/language_zh.xml index cbd651788..bc6826251 100755 --- a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_font/res/string/language_zh.xml +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_font/res/string/language_zh.xml @@ -7,45 +7,69 @@ value="图片" size="32" direct="rtl" - /> + /> + /> + /> + /> + /> + /> + /> + /> - + /> + + + + + + + \ No newline at end of file diff --git a/code/sdk/middleware/services/gui/uikit/utils/interfaces/innerkits/graphic_config.h b/code/sdk/middleware/services/gui/uikit/utils/interfaces/innerkits/graphic_config.h index 163e79977..54047edfb 100755 --- a/code/sdk/middleware/services/gui/uikit/utils/interfaces/innerkits/graphic_config.h +++ b/code/sdk/middleware/services/gui/uikit/utils/interfaces/innerkits/graphic_config.h @@ -369,7 +369,7 @@ namespace OHOS { /** * @brief vector font global ability, which is disabled by default on LiteOS. */ -#define ENABLE_FONT_VECTOR_GLOBAL 0 +#define ENABLE_FONT_VECTOR_GLOBAL 1 /** * @brief image bin ability, which is disabled by default on LiteOS. */