ConfigModel中json数据的读取与写入不在采用模板,现在是根据不同数据类型(字符串、数字、布尔值和数组大小)来使用相应的set和get函数来写入或读取JSON数据
authorluozheng <1732036298@qq.com>
Mon, 1 Apr 2024 04:55:49 +0000 (12:55 +0800)
committerluozheng <1732036298@qq.com>
Mon, 1 Apr 2024 04:55:49 +0000 (12:55 +0800)
16 files changed:
code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp
code/sdk/application/wearable/fd230app/nativeui/config/ConfigModel.json
code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h
code/sdk/application/wearable/fd230app/nativeui/config/src/ConfigModel.cpp
code/sdk/application/wearable/fd230app/nativeui/language/Language_xml/input_list_en.txt
code/sdk/application/wearable/fd230app/nativeui/language/Language_xml/input_list_zh.txt
code/sdk/application/wearable/fd230app/nativeui/language/Language_xml/language_en.xml
code/sdk/application/wearable/fd230app/nativeui/language/Language_xml/language_zh.xml
code/sdk/application/wearable/fd230app/nativeui/language/font/en.lang
code/sdk/application/wearable/fd230app/nativeui/language/font/ui_resource_string.h
code/sdk/application/wearable/fd230app/nativeui/language/font/zh.lang
code/sdk/application/wearable/fd230app/nativeui/language/include/LanguageSwitchModel.h
code/sdk/application/wearable/fd230app/nativeui/language/include/LanguageSwitchPresenter.h
code/sdk/application/wearable/fd230app/nativeui/language/src/LanguageSwitchModel.cpp
code/sdk/application/wearable/fd230app/nativeui/language/src/LanguageSwitchPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/language/src/LanguageSwitchView.cpp

index 50d1588..01bb17e 100644 (file)
@@ -37,7 +37,7 @@ namespace OHOS
         {VIEW_CALLER_LOG, PNG_APPLIST_CALLLOG_IMAGE, PNG_APPLIST_CALLLOG_IMAGE, "通话记录", nullptr},
         {VIEW_PHONE, PNG_APPLIST_CALLER_IMAGE, PNG_APPLIST_CALLER_IMAGE, "电话", nullptr},
         {VIEW_CONNECT_PHONE, PNG_CONNECT_PHONE_IMAGE, PNG_CONNECT_PHONE_IMAGE, "连接手机", nullptr},
-        {VIEW_LANGUAGE_SWITCH, PNG_CONNECT_PHONE_IMAGE, PNG_CONNECT_PHONE_IMAGE, "语言切换", nullptr},
+        //{VIEW_LANGUAGE_SWITCH, PNG_CONNECT_PHONE_IMAGE, PNG_CONNECT_PHONE_IMAGE, "语言切换", nullptr},
 #ifdef SUPPORT_ALIPAY_SEC
         {VIEW_MAIN_ALIPAY, PNG_APPLIST_ALIPAY_IMAGE, PNG_APPLIST_ALIPAY_IMAGE, "支付宝", nullptr},
 #endif
index 8850d8c..8386097 100644 (file)
@@ -6,5 +6,6 @@
     "HeartRateOrBloodOxygenQuickAccessSwitch": 0,
     "Dial_Id": 0,
     "Dial_Name": "KUMI",
-    "Language_Id": 0
+    "Language_Id": 0,
+    "Language_Code": "zh"
 }
\ No newline at end of file
index b42db7c..cf8caed 100644 (file)
@@ -7,6 +7,7 @@
 #include "../../../../../../open_source/openharmony/third_party/cJSON/cJSON.h"
 #include "wearable_log.h"
 #include "components/ui_image_animator.h"
+#include "vector"
 namespace OHOS
 {
     class ConfigModel
@@ -27,6 +28,23 @@ namespace OHOS
         T ReadJsonData(const cJSON *json_obj, const char *field_name);
         template <class T>
         void WriteJsonData(cJSON *json_obj, const char *field_name, T data);
+
+        /* -------------------------------------------------------------------------- */
+        std::string ReadJsonData_String(const cJSON *json_obj, const char *field_name);
+        double ReadJsonData_Number(const cJSON *json_obj, const char *field_name);
+        bool ReadJsonData_Bool(const cJSON *json_obj, const char *field_name);
+        int ReadJsonData_ArraySize(const cJSON *json_obj, const char *field_name);
+
+        void WriteJsonData_Int(cJSON *json_obj, const char *field_name, int data);
+        void WriteJsonData_Double(cJSON *json_obj, const char *field_name, double data);
+        void WriteJsonData_Bool(cJSON *json_obj, const char *field_name, bool data);
+        void WriteJsonData_String(cJSON *json_obj, const char *field_name, const char *data);
+        void WriteJsonData_VectorInt(cJSON *json_obj, const char *field_name, const std::vector<int> &data);
+        void WriteJsonData_VectorDouble(cJSON *json_obj, const char *field_name, const std::vector<double> &data);
+        void WriteJsonData_VectorString(cJSON *json_obj, const char *field_name, const std::vector<std::string> &data);
+        
+        void WriteJsonToFile(const char *json_string, const char *file_path);
+        /* -------------------------------------------------------------------------- */
         void ShowReadJsonData(void);
         void Init(void);
         /* -------------------------------- set与get方法 ------------------------------- */
@@ -50,7 +68,8 @@ namespace OHOS
         void Setimei(char *str);
         void SetpyVer(char *str);
         void SetmoderVer(char *str);
-
+        void SetLanguageCode(char *languagecode);
+        const char *GetLanguageCode(void);
         // -------------------------------------------------------------------------- */
     private:
         ConfigModel();                                        // 私有构造函数,确保无法在外部实例化
@@ -72,7 +91,7 @@ namespace OHOS
         char *imei_str = NULL;
         char *pyVer = NULL;
         char *moderVer = NULL;
-
+        std::string LanguageCode = "zh";
         cat1_msg_config cat1_msg_config_t;
         /* -------------------------------------------------------------------------- */
     };
@@ -150,6 +169,7 @@ namespace OHOS
             cJSON_ReplaceItemInObject(json_obj, field_name, data_obj);
 
             char *jsonString = cJSON_Print(json_obj);
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "有格式的方式打印Json:\n%s\n", jsonString);
             if (jsonString != nullptr)
             {
                 FILE *file = fopen(filePath.c_str(), "wb");
index 447d4f9..c9b5670 100644 (file)
@@ -4,12 +4,12 @@ namespace OHOS
 {
     ConfigModel::ConfigModel()
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " ConfigModel::ConfigModel");
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " ConfigModel::ConfigModel");
     }
 
     ConfigModel::~ConfigModel()
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " ConfigModel::~ConfigModel");
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " ConfigModel::~ConfigModel");
     }
 
     ConfigModel *ConfigModel::GetInstance()
@@ -45,6 +45,280 @@ namespace OHOS
         return false;
     }
 
+    /*1.读取字符串*/
+
+    /*
+     * @brief: 读取字符串
+     * @param {cJSON} json对象
+     * @param {char*} 字段名
+     * @return {std::string} 读取到的字符串
+     */
+    std::string ConfigModel::ReadJsonData_String(const cJSON *json_obj, const char *field_name)
+    {
+        const cJSON *field_item = cJSON_GetObjectItem(json_obj, field_name);
+        if (field_item != NULL && cJSON_IsString(field_item))
+        {
+            return std::string(field_item->valuestring);
+        }
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Field not found or not a string");
+        return "-1"; // 或者返回一个明确的错误字符串
+    }
+
+    /*
+     * @brief 读取数字
+     * @param {cJSON} json对象
+     * @param {char*} 字段名
+     * @return {double} 读取到的数字
+     */
+    double ConfigModel::ReadJsonData_Number(const cJSON *json_obj, const char *field_name)
+    {
+        const cJSON *field_item = cJSON_GetObjectItem(json_obj, field_name);
+        if (field_item != NULL && cJSON_IsNumber(field_item))
+        {
+            return field_item->valuedouble;
+        }
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Field not found or not a number");
+        return -1; // 或者返回一个错误值
+    }
+
+    /*
+     * @brief 读取布尔值
+     * @param {cJSON} json对象
+     * @param {char*} 字段名
+     * @return {bool} 读取到的布尔值
+     */
+    bool ConfigModel::ReadJsonData_Bool(const cJSON *json_obj, const char *field_name)
+    {
+        const cJSON *field_item = cJSON_GetObjectItem(json_obj, field_name);
+        if (field_item != NULL && cJSON_IsBool(field_item))
+        {
+            return field_item->valueint != 0;
+        }
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Field not found or not a boolean");
+        return false; // 或者返回一个错误值
+    }
+
+    /*
+     * @brief 读取数组大小
+     * @param {cJSON} json对象
+     * @param {char*} 字段名
+     * @return {int} 数组大小
+     */
+    int ConfigModel::ReadJsonData_ArraySize(const cJSON *json_obj, const char *field_name)
+    {
+        const cJSON *field_item = cJSON_GetObjectItem(json_obj, field_name);
+        if (field_item != NULL && cJSON_IsArray(field_item))
+        {
+            return cJSON_GetArraySize(field_item);
+        }
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Field not found or not an array");
+        return -1; // 或者返回一个错误值,表示没有找到或不是数组
+    }
+
+    /*
+     * @brief 写入int数据
+     * @param {cJSON} json对象
+     * @param {char*} 字段名
+     * @param {int}  要写入的数据
+     */
+    void ConfigModel::WriteJsonData_Int(cJSON *json_obj, const char *field_name, int data)
+    {
+        if (json_obj == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "json_obj is nullptr!");
+            return;
+        }
+
+        cJSON *data_obj = cJSON_CreateNumber(static_cast<double>(data));
+        if (data_obj != nullptr)
+        {
+            cJSON_ReplaceItemInObject(json_obj, field_name, data_obj);
+            char *jsonString = cJSON_Print(json_obj);
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "有格式的方式打印Json:\n%s\n", jsonString);
+            // Write to file as before
+            WriteJsonToFile(jsonString, filePath.c_str());
+        }
+        else
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to create cJSON object");
+        }
+    }
+
+    /*
+     * @brief 写入double数据
+     * @param {cJSON} json对象
+     * @param {char*} 字段名
+     * @param {double} 要写入的数据
+     */
+    void ConfigModel::WriteJsonData_Double(cJSON *json_obj, const char *field_name, double data)
+    {
+        if (json_obj == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "json_obj is nullptr!");
+            return;
+        }
+
+        cJSON *data_obj = cJSON_CreateNumber(data);
+        if (data_obj != nullptr)
+        {
+            cJSON_ReplaceItemInObject(json_obj, field_name, data_obj);
+            char *jsonString = cJSON_Print(json_obj);
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "有格式的方式打印Json:\n%s\n", jsonString);
+            // Write to file as before
+            WriteJsonToFile(jsonString, filePath.c_str());
+        }
+        else
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to create cJSON object");
+        }
+    }
+
+    /*
+     * @brief 写入Bool数据
+     * @param {cJSON} json对象
+     * @param {char*} 字段名
+     * @param {bool} 要写入的数据
+     */
+    void ConfigModel::WriteJsonData_Bool(cJSON *json_obj, const char *field_name, bool data)
+    {
+        if (json_obj == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "json_obj is nullptr!");
+            return;
+        }
+
+        cJSON *data_obj = cJSON_CreateBool(data);
+        if (data_obj != nullptr)
+        {
+            cJSON_ReplaceItemInObject(json_obj, field_name, data_obj);
+            char *jsonString = cJSON_Print(json_obj);
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "有格式的方式打印Json:\n%s\n", jsonString);
+            // Write to file as before
+            WriteJsonToFile(jsonString, filePath.c_str());
+        }
+        else
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to create cJSON object");
+        }
+    }
+
+    /*
+     * @brief 写入字符串数据
+     * @param {cJSON} json对象
+     * @param {char*} 字段名
+     * @param {const char *} 要写入的数据
+     */
+    void ConfigModel::WriteJsonData_String(cJSON *json_obj, const char *field_name, const char *data)
+    {
+        if (json_obj == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "json_obj is nullptr!");
+            return;
+        }
+
+        cJSON *data_obj = cJSON_CreateString(data);
+        if (data_obj != nullptr)
+        {
+            cJSON_ReplaceItemInObject(json_obj, field_name, data_obj);
+            char *jsonString = cJSON_Print(json_obj);
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "有格式的方式打印Json:\n%s\n", jsonString);
+            // Write to file as before
+            WriteJsonToFile(jsonString, filePath.c_str());
+        }
+        else
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to create cJSON object");
+        }
+    }
+
+    void ConfigModel::WriteJsonData_VectorInt(cJSON *json_obj, const char *field_name, const std::vector<int> &data)
+    {
+        if (json_obj == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "json_obj is nullptr!");
+            return;
+        }
+
+        cJSON *array_obj = cJSON_CreateArray();
+        for (const auto &item : data)
+        {
+            cJSON_AddItemToArray(array_obj, cJSON_CreateNumber(static_cast<double>(item)));
+        }
+        cJSON_ReplaceItemInObject(json_obj, field_name, array_obj);
+        char *jsonString = cJSON_Print(json_obj);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "有格式的方式打印Json:\n%s\n", jsonString);
+        // Write to file as before
+        WriteJsonToFile(jsonString, filePath.c_str());
+    }
+
+    void ConfigModel::WriteJsonData_VectorDouble(cJSON *json_obj, const char *field_name, const std::vector<double> &data)
+    {
+        if (json_obj == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "json_obj is nullptr!");
+            return;
+        }
+
+        cJSON *array_obj = cJSON_CreateArray();
+        for (const auto &item : data)
+        {
+            cJSON_AddItemToArray(array_obj, cJSON_CreateNumber(item));
+        }
+        cJSON_ReplaceItemInObject(json_obj, field_name, array_obj);
+        char *jsonString = cJSON_Print(json_obj);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "有格式的方式打印Json:\n%s\n", jsonString);
+        // Write to file as before
+        WriteJsonToFile(jsonString, filePath.c_str());
+    }
+
+    void ConfigModel::WriteJsonData_VectorString(cJSON *json_obj, const char *field_name, const std::vector<std::string> &data)
+    {
+        if (json_obj == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "json_obj is nullptr!");
+            return;
+        }
+
+        cJSON *array_obj = cJSON_CreateArray();
+        for (const auto &item : data)
+        {
+            cJSON_AddItemToArray(array_obj, cJSON_CreateString(item.c_str()));
+        }
+        cJSON_ReplaceItemInObject(json_obj, field_name, array_obj);
+        char *jsonString = cJSON_Print(json_obj);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "有格式的方式打印Json:\n%s\n", jsonString);
+        // Write to file as before
+        WriteJsonToFile(jsonString, filePath.c_str());
+    }
+
+    /*
+     * @brief 写入 JSON 数据到文件
+     * @param {char} json字符串
+     * @param {char} json文件路径
+     */
+    void ConfigModel::WriteJsonToFile(const char *json_string, const char *file_path)
+    {
+        if (json_string == NULL || file_path == NULL)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Invalid input parameters!");
+            return;
+        }
+
+        FILE *fp = fopen(file_path, "w+");
+        if (fp == NULL)
+        {
+            printf("Failed to open file: %s\n", file_path);
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to open file: %s", file_path);
+            return;
+        }
+
+        fputs(json_string, fp);
+        fclose(fp);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "JSON data written to file: %s", file_path);
+    }
+
+    /* -------------------------------------------------------------------------- */
+
     void ConfigModel::Init(void)
     {
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ConfigModel::Init");
@@ -153,6 +427,18 @@ namespace OHOS
         return languageid_;
     }
 
+    void ConfigModel::SetLanguageCode(char *languagecode)
+    {
+        LanguageCode = languagecode;
+        WriteJsonData_String(GetcJSON(), "Language_Code", LanguageCode.c_str()); // 应该放到关机时候写
+    }
+
+    const char *ConfigModel::GetLanguageCode(void)
+    {
+        LanguageCode = ReadJsonData_String(GetcJSON(), "Language_Code"); // 应该放到开机时候读
+        return LanguageCode.c_str();
+    }
+
     char *ConfigModel::Getimei()
     {
         return imei_str;
index 5f4175c..067d7d6 100644 (file)
@@ -186,4 +186,5 @@ STR_DANCING_TITLE,Dance Sport
 STR_BALL_LIST_TITLE,Ball Sport\r
 STR_OTHER_TITLE,Other Sport\r
 STR_EXERCISE_TITLE,Exercise Sport\r
-STR_TRAINING,Training
\ No newline at end of file
+STR_TRAINING,Training\r
+STR_LANGUAGE,Language
\ No newline at end of file
index 1660372..d3ab46d 100644 (file)
@@ -186,4 +186,5 @@ STR_DANCING_TITLE,舞蹈运动
 STR_BALL_LIST_TITLE,球类运动\r
 STR_OTHER_TITLE,其他运动\r
 STR_EXERCISE_TITLE,健身运动\r
-STR_TRAINING,训练
\ No newline at end of file
+STR_TRAINING,训练\r
+STR_LANGUAGE,语言
\ No newline at end of file
index 84d8e09..3dc014a 100644 (file)
        <lanstr id="STR_OTHER_TITLE" value="Other Sport"/>
        <lanstr id="STR_EXERCISE_TITLE" value="Exercise Sport"/>
        <lanstr id="STR_TRAINING" value="Training"/>
+       <lanstr id="STR_LANGUAGE" value="Language"/>
 </language>
index 7604c2f..c9ceec3 100644 (file)
        <lanstr id="STR_OTHER_TITLE" value="其他运动"/>
        <lanstr id="STR_EXERCISE_TITLE" value="健身运动"/>
        <lanstr id="STR_TRAINING" value="训练"/>
+       <lanstr id="STR_LANGUAGE" value="语言"/>
 </language>
index a3ed1b8..972b118 100644 (file)
Binary files a/code/sdk/application/wearable/fd230app/nativeui/language/font/en.lang and b/code/sdk/application/wearable/fd230app/nativeui/language/font/en.lang differ
index ba90556..150dc61 100644 (file)
@@ -1,15 +1,15 @@
-/*
-* 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 <cstdint>
-namespace OHOS {
-enum UIResourceTextId : uint16_t {
+/*\r
+* Copyright (c) xxxxxxxx Technologies Co., Ltd. 2021-2021. All rights reserved.\r
+* Description: language\r
+* Author: Graphic develop team\r
+* Create: 2021-07-06\r
+*/\r
+\r
+#ifndef UI_RESOURCE_STRING_H\r
+#define UI_RESOURCE_STRING_H\r
+#include <cstdint>\r
+namespace OHOS {\r
+enum UIResourceTextId : uint16_t {\r
     STR_EXERCISE_GENERAL = 0,\r
     STR_EXERCISE_FREETRAINING = 1,\r
     STR_EXERCISE_RESISTANCETRAINING = 2,\r
@@ -198,10 +198,11 @@ enum UIResourceTextId : uint16_t {
     STR_OTHER_TITLE = 185,\r
     STR_EXERCISE_TITLE = 186,\r
     STR_TRAINING = 187,\r
-    STR_MAX_ID = 188,\r
+    STR_LANGUAGE = 188,\r
+    STR_MAX_ID = 189,\r
 }; // UIResourceTextId\r
-
-enum FontLanguageId : uint8_t {
+\r
+enum FontLanguageId : uint8_t {\r
     LANGUAGE_ID_ZH,\r
     LANGUAGE_ID_EN,\r
     LANGUAGE_ID_MAX\r
index 18730d3..98c9f70 100644 (file)
Binary files a/code/sdk/application/wearable/fd230app/nativeui/language/font/zh.lang and b/code/sdk/application/wearable/fd230app/nativeui/language/font/zh.lang differ
index 93b43f5..7b43737 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-03-28 16:36:58
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-03-30 15:31:58
+ * @LastEditTime: 2024-03-30 21:10:24
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/language/include/LanguageSwitchModel.h
  */
 
@@ -10,7 +10,7 @@
 #define LANGUAGE_SWITCH_MODEL_H
 
 #include "language/include/LanguageSwitchListAdapter.h"
-
+#include "config/include/ConfigModel.h"
 namespace OHOS
 {
 
@@ -18,19 +18,20 @@ namespace OHOS
     {
     public:
         static LanguageSwitchModel &GetInstance();
-        void SetCurLanguageCode(char * curlanguageid);
-        char * GetCurLanguageCode(void);
-        void SetLastLanguageCode(char * prelanguageid);
-        char * GetLastLanguageCode(void);
+        void SetCurLanguageCode(char *curlanguageid);
+        char *GetCurLanguageCode(void);
+        void SetLastLanguageCode(char *prelanguageid);
+        char *GetLastLanguageCode(void);
 
     private:
-        LanguageSwitchModel() {}
-        ~LanguageSwitchModel() {}
+        LanguageSwitchModel();
+        ~LanguageSwitchModel();
         LanguageSwitchModel(const LanguageSwitchModel &) = delete;
         const LanguageSwitchModel &operator=(const LanguageSwitchModel &) = delete;
         static const uint16_t LANGUAGE_ITEM_MAX = MAX_LANGUAGE; // 语言总数
-        char *CurLanguageCode = "zh";                             // 当前语言,默认简体中文
-        char *PreLanguageCode = nullptr;                          // 上一次切换的语言
+        char *CurLanguageCode = "zh";                           // 当前语言,默认简体中文
+        char *PreLanguageCode = nullptr;                        // 上一次切换的语言
+        ConfigModel *p_ConfigModel{nullptr};
     };
 
 }
index c0015eb..b633ab3 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-03-28 14:16:52
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-03-30 16:15:40
+ * @LastEditTime: 2024-03-30 20:35:38
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/language/include/LanguageSwitchPresenter.h
  */
 #ifndef LANGUAGE_SWITCH_PRESENTER_H
@@ -13,6 +13,7 @@
 #include "language/include/LanguageSwitchModel.h"
 #include "LanguageSwitchView.h"
 #include "language/include/LanguageSwitchListitemView.h"
+#include "language/font/ui_resource_string.h"
 namespace OHOS
 {
 
index 41cc825..0875e9a 100644 (file)
@@ -2,16 +2,29 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-03-28 16:36:46
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-03-30 15:29:41
+ * @LastEditTime: 2024-04-01 11:52:27
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/language/src/LanguageSwitchModel.cpp
  */
 #include "language/include/LanguageSwitchModel.h"
 #include "wearable_log.h"
 #include "language/LanguageInit.h"
-
 namespace OHOS
 {
 
+    LanguageSwitchModel::LanguageSwitchModel()
+    {
+        p_ConfigModel = ConfigModel::GetInstance();
+        if (p_ConfigModel->GetLanguageCode() != nullptr)
+        {
+            //printf("%s\n", p_ConfigModel->GetLanguageCode());
+            CurLanguageCode = const_cast<char *>(p_ConfigModel->GetLanguageCode());
+        }
+    }
+
+    LanguageSwitchModel::~LanguageSwitchModel()
+    {
+    }
+
     LanguageSwitchModel &LanguageSwitchModel::GetInstance()
     {
         static LanguageSwitchModel instance;
@@ -21,7 +34,7 @@ namespace OHOS
     /*
      * @brief: 设置当前语言code
      */
-    void LanguageSwitchModel::SetCurLanguageCode(char * curlanguagecode)
+    void LanguageSwitchModel::SetCurLanguageCode(char *curlanguagecode)
     {
         CurLanguageCode = curlanguagecode;
     }
@@ -29,7 +42,7 @@ namespace OHOS
     /*
      * @brief 获取当前设置的语言code
      */
-    char * LanguageSwitchModel::GetCurLanguageCode(void)
+    char *LanguageSwitchModel::GetCurLanguageCode(void)
     {
         return CurLanguageCode;
     }
@@ -37,7 +50,7 @@ namespace OHOS
     /*
      * @brief 设置上一次语言code
      */
-    void LanguageSwitchModel::SetLastLanguageCode(char * prelanguagecode)
+    void LanguageSwitchModel::SetLastLanguageCode(char *prelanguagecode)
     {
         PreLanguageCode = prelanguagecode;
     }
@@ -45,7 +58,7 @@ namespace OHOS
     /*
      * @brief 获取上一次设置的语言code
      */
-    char * LanguageSwitchModel::GetLastLanguageCode(void)
+    char *LanguageSwitchModel::GetLastLanguageCode(void)
     {
         return PreLanguageCode;
     }
index 2e5828d..17cf4fe 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-03-28 14:17:43
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-03-30 16:35:37
+ * @LastEditTime: 2024-04-01 11:21:08
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/language/src/LanguageSwitchPresenter.cpp
  */
 #include "AppViewIDs.h"
@@ -115,8 +115,8 @@ namespace OHOS
         {
             LanguageId currentLanguageId = LanguageManager::GetInstance().GetLanguageIdByCode(p_LanguageSwitchModel->GetCurLanguageCode());
             g_planguage->ChangeLanguage(currentLanguageId);
-
-            m_labelext->SetTextId(0);
+            ConfigModel::GetInstance()->SetLanguageCode(p_LanguageSwitchModel->GetCurLanguageCode());
+            m_labelext->SetTextId(STR_LANGUAGE);
             m_labelext->ForceResetText();// 强制刷新
 
             p_UILabelButtonExt->SetImageSrc(SelectedImg, SelectedImg);
index 1a15db9..55dcc12 100644 (file)
@@ -4,11 +4,13 @@
 namespace OHOS
 {
 
-    static constexpr int16_t TITLE_LABEL_X = 133;
+    static constexpr int16_t TITLE_LABEL_X = 83;
     static constexpr int16_t TITLE_LABEL_Y = 52;
-    static constexpr int16_t TITLE_LABEL_W = 20;
+    static constexpr int16_t TITLE_LABEL_W = 300;
     static constexpr int16_t TITLE_LABEL_H = 40;
-
+    static constexpr int16_t TITLE_LABEL_TEXT_FONT = 30;
+    static constexpr int16_t TITLE_LABEL_LINE_HEIGHT = 35;
+    static constexpr int16_t TITLE_LABEL_TEXT_ROLLSPEED = 40;
 
     static constexpr int16_t LANGUAGE_LIST_X = 43;
     static constexpr int16_t LANGUAGE_LIST_Y = 120;
@@ -89,14 +91,14 @@ namespace OHOS
             return false;
         }
         LanguageSwitchViewTitleLabel->SetPosition(TITLE_LABEL_X, TITLE_LABEL_Y, TITLE_LABEL_W, TITLE_LABEL_H);
-        LanguageSwitchViewTitleLabel->SetStyle(STYLE_TEXT_FONT, 30);
-        LanguageSwitchViewTitleLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
+        LanguageSwitchViewTitleLabel->SetStyle(STYLE_TEXT_FONT, TITLE_LABEL_TEXT_FONT);
+        LanguageSwitchViewTitleLabel->SetStyle(STYLE_LINE_HEIGHT, TITLE_LABEL_LINE_HEIGHT);
         // LanguageSwitchViewTitleLabel->SetText("语言");
-        LanguageSwitchViewTitleLabel->SetTextId(0);
+        LanguageSwitchViewTitleLabel->SetTextId(STR_LANGUAGE);
         LanguageSwitchViewTitleLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
         LanguageSwitchViewTitleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
-        LanguageSwitchViewTitleLabel->SetRollSpeed(40);
-        LanguageSwitchViewTitleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+        LanguageSwitchViewTitleLabel->SetRollSpeed(TITLE_LABEL_TEXT_ROLLSPEED);
+        LanguageSwitchViewTitleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TITLE_LABEL_TEXT_FONT);
         LanguageSwitchPresenter::GetInstance()->SetLabelExt(LanguageSwitchViewTitleLabel);
         return true;
     }