From 154dd3b06963a32b7e542225adf08ced150dd096 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=A2=81=E6=B8=85=E6=A2=A6?= <3449750381@qq.com> Date: Sat, 27 Jul 2024 05:50:49 +0000 Subject: [PATCH] Merge #605 into sdk602patch0626 from refs/changes/605/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Code review from 袁清梦 * refs/changes/605/head: (13 commits squashed) - 增加自定义表盘配置文件相对应接口 - 修复maomao表盘异常 - 暂时屏蔽自定义表盘配置文件读取 - 取消训练状态下的心率存储 - 增加runtime训练状态管理 - Merge branch 'sdk602patch0626' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0626 - Merge branch 'sdk602patch0626' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0626 - Merge branch 'sdk602patch0626' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0626 - 增加自定义表盘对应接口(已验证本地自定义表盘配置) - Merge branch 'sdk602patch0626' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0626 - Merge branch 'sdk602patch0626' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0626 - 修复主界面切换表盘卡死 - Merge branch 'sdk602patch0626' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0626 Signed-off-by: Caisking <3449750381@qq.com> Reviewed-by: snickersun@163.com Merged-by: snickersun@163.com CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/605 --- .../nativelauncher/include/UiConfig.h | 33 ++- .../nativeui/clock/include/MainClockView.h | 7 +- .../nativeui/clock/src/MainClockView.cpp | 23 +- .../nativeui/main/include/MainModel.h | 28 +-- .../fd230app/nativeui/main/src/MainModel.cpp | 131 +++++----- .../nativeui/main/src/MainViewSample.cpp | 17 +- .../nativeui/set_dial/include/SetDialInfo.h | 18 +- .../nativeui/set_dial/include/SetDialModel.h | 35 +-- .../nativeui/set_dial/src/SetDialModel.cpp | 229 ++++++++++-------- .../nativeui/set_dial/src/SetDialView.cpp | 19 +- 10 files changed, 278 insertions(+), 262 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h index a0e091e7f..28fdf4f52 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h @@ -34,10 +34,10 @@ namespace OHOS typedef enum { DIAL_CLOCK = 0, - DIAL_CLOCK_2 = 1, - DIAL_CLOCK_3 = 2, - DIAL_CLOCK_4 = 3, - DIAL_CLOCK_5 = 4, + DIAL_CLOCK_1 = 1, + DIAL_CLOCK_2 = 2, + DIAL_CLOCK_3 = 3, + DIAL_CLOCK_4 = 4, DIAL_MAX, } DialId; @@ -66,13 +66,14 @@ namespace OHOS #define APP_RES_PATH "/user/res" #define APP_MUSIC_PATH "/user/music" #define APP_VIDEO_PATH "/user/video" -#define APP_DEFAULT_DIAL_PATH "/user/dial" /*默认表盘安装路径*/ -#define APP_DOWNLOAD_DIAL_PATH "/user/userdata/dial" /*表盘市场安装路径*/ -#define APP_CUSTOM_DIAL_PATH "/user/userdata/constom_dial" /*自定义表盘安装路径*/ +#define APP_DEFAULT_DIAL_PATH "/user/dial" /*默认表盘安装路径*/ +#define APP_DOWNLOAD_DIAL_PATH "/user/userdata/dial" /*表盘市场安装路径*/ +#define APP_CUSTOM_DIAL_PATH "/user/userdata/custom_dial" /*自定义表盘安装路径*/ #define APP_LIST_PATH "/user/res/applist_icon" - /* ---------------------------------- 卡片管理 --------------------------------- */ + static constexpr const char *CARD_CONFIG_PATH = "/user/cardconfig.bin"; - static constexpr const char *DEFAULT_DIAL_PATH = APP_RES_PATH "/dial_soures/KUMI.bin"; + + /* --------------------------------- 自定义表盘配置 -------------------------------- */ #ifdef CUSTOM_Z1 static constexpr const char *DEFAULT_DIALBACK_PATH = APP_RES_PATH "/dial_soures/z1background.bin"; static constexpr const char *DEFAULT_DIALPER_PATH = APP_RES_PATH "/dial_soures/Z1VIEW.bin"; @@ -80,10 +81,16 @@ namespace OHOS static constexpr const char *DEFAULT_DIALBACK_PATH = APP_RES_PATH "/dial_soures/MAIN_FACE_IMAGE.bin"; static constexpr const char *DEFAULT_DIALPER_PATH = APP_RES_PATH "/dial_soures/KUMIVIEW.bin"; #endif - - // static constexpr const char *DEFAULT_DIALPER_PATH_TEST = APP_CUSTOM_DIAL_PATH"/Classic_Geometry.bin"; - // static constexpr const char *DEFAULT_DIALPER_PATH_TEST = APP_CUSTOM_DIAL_PATH"/Classic_Geometry.bin"; - + static constexpr const char *CUSTOM_CLOCK1_DIALBACK_PATH = APP_CUSTOM_DIAL_PATH "/1/main_bg.bin"; + static constexpr const char *CUSTOM_CLOCK1_DIALPER_PATH = APP_CUSTOM_DIAL_PATH "/1/thumbnail.bin"; + static constexpr const char *CUSTOM_CLOCK2_DIALBACK_PATH = APP_CUSTOM_DIAL_PATH "/2/main_bg.bin"; + static constexpr const char *CUSTOM_CLOCK2_DIALPER_PATH = APP_CUSTOM_DIAL_PATH "/2/thumbnail.bin"; + static constexpr const char *CUSTOM_CLOCK3_DIALBACK_PATH = APP_CUSTOM_DIAL_PATH "/3/main_bg.bin"; + static constexpr const char *CUSTOM_CLOCK3_DIALPER_PATH = APP_CUSTOM_DIAL_PATH "/3/thumbnail.bin"; + static constexpr const char *CUSTOM_CLOCK4_DIALBACK_PATH = APP_CUSTOM_DIAL_PATH "/4/main_bg.bin"; + static constexpr const char *CUSTOM_CLOCK4_DIALPER_PATH = APP_CUSTOM_DIAL_PATH "/4/thumbnail.bin"; + /* -------------------------------------------------------------------------- */ + /*卡片管理*/ static constexpr const char *PNG_SET_CARD_ADD = APP_RES_PATH "/MainCard/CARD_ADD.bin"; static constexpr const char *PNG_SET_CARD_DEL = APP_RES_PATH "/MainCard/CARD_DEL.bin"; static constexpr const char *PNG_SET_CARD_HEART = APP_RES_PATH "/MainCard/HeartCard.bin"; diff --git a/code/sdk/application/wearable/fd230app/nativeui/clock/include/MainClockView.h b/code/sdk/application/wearable/fd230app/nativeui/clock/include/MainClockView.h index 5c4920735..7772895eb 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/clock/include/MainClockView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/clock/include/MainClockView.h @@ -90,14 +90,16 @@ namespace OHOS void UpdateBatteryColor(void); /*配置文件*/ void SetDialPath(std::string dialpath); - + + /*配置自定义表盘*/ + void SetCustomId(int Id); + /*配置函数*/ bool InitBackground(const char *filename); bool InitTimeView(TimeDisplayPosition type); // 时间 bool InitBatteryView(BatteryDisplayType type); // 电量 bool InitColor(ColorTypeSet type); // 颜色 - private: void InitStepValue(); bool InitLabelView(void); @@ -107,7 +109,6 @@ namespace OHOS bool InitClock(void); bool LoadClockImage(Image *view, uint32_t resId); bool LoadClockImage(UIImageView *view, uint32_t resId); - /*表盘背景*/ UIImageView *curFace{nullptr}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/clock/src/MainClockView.cpp b/code/sdk/application/wearable/fd230app/nativeui/clock/src/MainClockView.cpp index 87739fb10..a5e5bdc96 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/clock/src/MainClockView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/clock/src/MainClockView.cpp @@ -28,6 +28,7 @@ #include "main/include/PullUpDownView.h" #include "battery_hal.h" #include "message/include/MessageControlView.h" +#include "SetDialModel.h" extern uint8_t battery_get_voltage(float *voltage); #define TIMEVIEW_UP 0 @@ -125,6 +126,26 @@ namespace OHOS { return g_pMainClockView; } + /*配置自定义表盘*/ + void MainClockView::SetCustomId(int Id) + { + // 默认表盘和异常表盘采用原表盘配置 + if (Id == DIAL_CLOCK || Id > DIAL_MAX) + return; + + DialLayout dialconfig; + SetDialModel::GetInstance().loadDialConfig(Id, dialconfig); + + // 设置背景 + dialFile = SetDialModel::GetInstance().GetSaveDir(Id) + "/" + "main_bg.bin"; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dialFile is %s", dialFile.c_str()); + + // 设置表盘配置 + timePosition = static_cast(dialconfig.timeDisplay); + batterySetting = static_cast(dialconfig.batteryDisplay); + colorType = static_cast(dialconfig.colorTypeSet); + } + /*设置表盘背景*/ void MainClockView::SetDialPath(std::string dialpath) { @@ -158,7 +179,7 @@ namespace OHOS ImageInfo *image = ImageCacheManager::GetInstance().LoadSingleRes(filename, false); if (image == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LoadAllDialFromRam loadimage %s fail", + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadAllDialFromRam loadimage %s fail", filename); curFace->SetSrc(DEFAULT_DIALBACK_PATH); Add(curFace); diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/include/MainModel.h b/code/sdk/application/wearable/fd230app/nativeui/main/include/MainModel.h index 65f44fae1..f2ac1acdc 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/include/MainModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/main/include/MainModel.h @@ -1,27 +1,4 @@ -/*** - * @Date: 2024-06-21 09:56:18 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-07-06 15:15:38 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/main/include/MainModel.h - */ -/*** - * @Date: 2024-06-21 09:56:18 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-06-28 16:36:39 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/main/include/MainModel.h - */ -/*** - * @Date: 2024-06-21 09:56:18 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-06-27 09:38:03 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/main/include/MainModel.h - */ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: MainModel.h - * Author: - * Create: 2021-11-23 - */ + #ifndef MAIN_MODEL_H #define MAIN_MODEL_H @@ -42,6 +19,7 @@ namespace OHOS CardId id; bool isVisible; }; + // 自定义表盘配置 typedef struct { DialId id; @@ -80,7 +58,7 @@ namespace OHOS const bool GetCardInfoSet(uint8_t index) const; private: - void InitDialSettingDefault(void); + void InitDialSettingDefault(int Id); MainModel(); MainModel(const MainModel &); MainModel &operator=(const MainModel &); diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainModel.cpp index 6788aaf4e..bc1debf7f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainModel.cpp @@ -38,14 +38,18 @@ namespace OHOS {GOAL, false}, {SLEEP, false}, }; - /*自定义map?*/ + /*自定义map配置*/ const DialInfo dialInfoMap[] = { - #ifdef CUSTOM_Z1 +#ifdef CUSTOM_Z1 {DIAL_CLOCK, "Z1", DEFAULT_DIALPER_PATH, DEFAULT_TASK_PERIOD}, - #else - {DIAL_CLOCK, "KUMI", DEFAULT_DIALPER_PATH, DEFAULT_TASK_PERIOD},//默认 +#else + {DIAL_CLOCK, "KUMI", DEFAULT_DIALPER_PATH, DEFAULT_TASK_PERIOD}, // 默认表盘 Id 0 + {DIAL_CLOCK_1, "Custom_1", CUSTOM_CLOCK1_DIALPER_PATH, DEFAULT_TASK_PERIOD}, // 表盘 Id 1 + {DIAL_CLOCK_2, "Custom_2", CUSTOM_CLOCK2_DIALPER_PATH, DEFAULT_TASK_PERIOD}, // 表盘 Id 2 + {DIAL_CLOCK_3, "Custom_3", CUSTOM_CLOCK3_DIALPER_PATH, DEFAULT_TASK_PERIOD}, // 表盘 Id 3 + {DIAL_CLOCK_4, "Custom_4", CUSTOM_CLOCK4_DIALPER_PATH, DEFAULT_TASK_PERIOD}, // 表盘 Id 4 - #endif +#endif }; const CardInfo printfMap[] = { @@ -360,76 +364,89 @@ namespace OHOS return nullptr; } - void MainModel::InitDialSettingDefault(void) + void MainModel::InitDialSettingDefault(int id) { + if (id < DIAL_CLOCK || id >= DIAL_MAX) + id = DIAL_CLOCK; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "InitDialSettingDefault"); dialSetting.dialFlag = 0; - dialSetting.dialId = DIAL_CLOCK; - dialSetting.dialFullName = ""; + dialSetting.dialId = id; + dialSetting.dialFullName.clear(); // 用 clear() 替代空字符串 } - /*更新表盘设置*/ + /* 更新表盘设置 */ void MainModel::AddDialSetting(const DialSetting &setting, const int id) { - std::string tmp; - tmp += std::to_string(setting.dialFlag) + ","; - tmp += std::to_string(setting.dialId) + ","; - tmp += setting.dialFullName + ","; + std::string tmp = std::to_string(setting.dialFlag) + "," + std::to_string(setting.dialId) + "," + setting.dialFullName + ","; - (void)UtilsSetValue("dial_setting", tmp.c_str()); - (void)UtilsSetValue("dial_id", std::to_string(id).c_str()); + (void)UtilsSetValue("dial_setting", tmp.c_str()); // 存储表盘配置 + (void)UtilsSetValue("dial_id", std::to_string(id).c_str()); // 存储当前表盘Id } - /*加载kvstore里面的dial*/ + + /* 加载 kvstore 里面的 dial */ void MainModel::InitDialSettings(void) { - char temp[DIAL_SETTING_VALUE_LEN] = {0}; - int len; - len = UtilsGetValue("dial_setting", temp, DIAL_SETTING_VALUE_LEN); - if (len >= 0) + char temp[DIAL_SETTING_VALUE_LEN] = {0}; // 创建一个临时字符数组用于存储拨号设置的字符串 + int len = UtilsGetValue("dial_setting", temp, DIAL_SETTING_VALUE_LEN); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "Attempting to load dial settings from kvstore. Length: %d\r\n", len); + + if (len < 0) { - char *setBuffer = nullptr; - char *setValue = strtok_s(temp, ",", &setBuffer); - if (setValue != nullptr) - { - dialSetting.dialFlag = atoi(setValue); - } - else - { - InitDialSettingDefault(); - return; - } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: Failed to retrieve dial settings. Initializing to default settings.\r\n"); + InitDialSettingDefault(DIAL_CLOCK); + return; + } - setValue = strtok_s(nullptr, ",", &setBuffer); - if (setValue != nullptr) - { - dialSetting.dialId = atoi(setValue); - } - else - { - InitDialSettingDefault(); - return; - } + char *setBuffer = nullptr; // 字符指针用于 strtok_s 的存储 + char *setValue; - setValue = strtok_s(nullptr, ",", &setBuffer); - if (setValue != nullptr) - { - dialSetting.dialFullName = setValue; - if (!((dialSetting.dialFullName.length() > 0) && - (access(dialSetting.dialFullName.c_str(), F_OK) == 0))) - { - InitDialSettingDefault(); - return; - } - } - else + // 从字符串中读取三个值 + // 1.读取表盘标志位 + setValue = strtok_s(temp, ",", &setBuffer); + if (setValue) + { + dialSetting.dialFlag = atoi(setValue); // 将字符串转换为整数 + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "Dial flag loaded: %d\r\n", dialSetting.dialFlag); + } + else + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: First value is empty. Initializing to default settings.\r\n"); + InitDialSettingDefault(DIAL_CLOCK); + return; + } + + // 读取表盘Id + setValue = strtok_s(nullptr, ",", &setBuffer); + if (setValue) + { + dialSetting.dialId = atoi(setValue); // 将字符串转换为整数 + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "Dial ID loaded: %d\r\n", dialSetting.dialId); + } + else + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: Second value is empty. Initializing to default settings.\r\n"); + InitDialSettingDefault(DIAL_CLOCK); + return; + } + + // 读取表盘名 + setValue = strtok_s(nullptr, ",", &setBuffer); + if (setValue) + { + dialSetting.dialFullName = setValue; // 将完整名称赋值 + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "Dial full name loaded: %s\r\n", dialSetting.dialFullName.c_str()); + + if (dialSetting.dialFullName.empty() || access(dialSetting.dialFullName.c_str(), F_OK) != 0) { - InitDialSettingDefault(); - return; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: Dial full name is invalid or file does not exist. Initializing to default settings.\r\n"); + InitDialSettingDefault(dialSetting.dialId); } } else { - InitDialSettingDefault(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: Third value is empty. Initializing to default settings.\r\n"); + InitDialSettingDefault(dialSetting.dialId); } } @@ -437,9 +454,7 @@ namespace OHOS { return dialSetting; } - } - #if 0 void MainModel::DeleteCardSetting(uint8_t index) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp index 4eb104635..30434092d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp @@ -238,6 +238,7 @@ namespace OHOS bool MainViewSample::HorizontalViewInit(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::HorizontalViewInit"); + /*读取kvstore里面的配置*/ presenter_->InitDialSettings(); presenter_->InitCardSettings(); uint8_t cardSettingNum = presenter_->GetCardSettingCount(); @@ -369,21 +370,9 @@ namespace OHOS UICardPage *MainViewSample::InitWatchDial(DialSetting &setting) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::InitWathDial"); -#if 0 - switch (setting.dialId) - { - case DIAL_CLOCK: - { - return new MainClockView(); - } - break; // 添加 break 语句 - default: - return nullptr; - } -#endif + MainClockView *clock = new MainClockView(); - clock->SetDialPath(setting.dialFullName); - // clock->InitialConfig(setting.dialId); //配置文件 + clock->SetCustomId(setting.dialId); return clock; } UICardPage *MainViewSample::InitWatchFacePage(void) diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialInfo.h b/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialInfo.h index 2de65cf48..158370c9c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialInfo.h +++ b/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialInfo.h @@ -11,14 +11,16 @@ #include #include #include "common/image_cache_manager.h" -namespace OHOS { - typedef struct { - uint8_t dialFlag; /* 1:离线表盘 0:预制表盘 */ - uint8_t id; /* 仅预制表盘使用 */ - std::string dialFullName; /* 仅离线表盘使用 */ - std::string imageFullName; /* 仅预制表盘使用 */ - std::string dialName; - std::string description; /* 仅离线表盘使用 */ +namespace OHOS +{ + typedef struct + { + uint8_t dialFlag; // 表盘标志 1:离线表盘 0:预制表盘 + uint8_t id; // 表盘Id 仅预制表盘使用 + std::string dialFullName; // 表盘路径 仅离线表盘使用 + std::string imageFullName; // 表盘缩约图 仅预制表盘使用 + std::string dialName; // 表盘名 + std::string description; // 表盘描述 仅离线表盘使用 ImageInfo *preImageInfo; } SetDialInfo; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModel.h b/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModel.h index 30ea317fb..41d84fdf1 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModel.h @@ -1,27 +1,3 @@ -/*** - * @Date: 2024-06-17 11:38:34 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-07-02 20:41:18 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModel.h - */ -/*** - * @Date: 2024-06-17 11:38:34 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-06-21 11:13:24 - * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModel.h - */ -/*** - * @Date: 2024-05-30 15:59:37 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-06-14 16:51:13 - * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModel.h - */ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: SetDialModel.h - * Author: - * Create: 2021-11-23 - */ #ifndef SET_DIAL_MODEL_H #define SET_DIAL_MODEL_H @@ -39,9 +15,9 @@ namespace OHOS struct DialLayout { uint8_t dialId; - uint8_t batteryDisplay; // 电池配置 - uint8_t timeDisplay; // 时间位置 - uint8_t colorTypeSet; // 颜色配置 + uint8_t batteryDisplay; // 电池配置 [0:无 1:白 2:黑] + uint8_t timeDisplay; // 时间位置 [0:上 1:下] + uint8_t colorTypeSet; // 颜色配置 [0:白 1:黑 2:灰 3:绿 4:橙 5:蓝] }; class SetDialModel { @@ -71,6 +47,11 @@ namespace OHOS std::string GetSaveDir(int Id); /*【判断文件夹是否存在 不存在创建】*/ void CreateDirectoryIfNotExists(const std::string &path); + /*判断文件是否存在*/ + bool CheckFileExists(const std::string &filePath); + /*获取自定义表盘名*/ + std::string GetCustomName(int Id); + void TestDialConfig(void); private: void LoadAllDialFromRam(void); diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialModel.cpp index e60864a26..99bf4d039 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialModel.cpp @@ -1,21 +1,4 @@ -/*** - * @Date: 2024-06-17 19:06:05 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-06-17 19:06:53 - * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialModel.cpp - */ -/*** - * @Date: 2024-05-30 15:59:37 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-06-12 10:26:15 - * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialModel.cpp - */ -/* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: SetDialModel.cpp - * Author: - * Create: 2021-11-23 - */ + #include #include "MainModel.h" #include "SetDialModel.h" @@ -125,16 +108,15 @@ namespace OHOS size -= (DIAL_ID_LENGTH + DIAL_NAME_LENGTH); } - // free(buf); fclose(fp); return true; } SetDialModel::SetDialModel() { - readDialfile(); - LoadAllDial(); - char idBuffer[10]; + readDialfile(); // 读取表盘map配置文件 + LoadAllDial(); // 更新表盘个数 当前表盘 + char idBuffer[10]; // 读取表盘Id配置文件 int len = UtilsGetValue("dial_id", idBuffer, sizeof(idBuffer)); if (len >= 0) { @@ -164,6 +146,7 @@ namespace OHOS saveDialfile(); } + /* 打印map */ void SetDialModel::PrintRegisteredDials(const std::unordered_map &dials) { @@ -173,6 +156,7 @@ namespace OHOS printf("ID: %u | Name: %s\n", entry.first, entry.second.c_str()); } } + /* 通过名字查询Id */ uint16_t SetDialModel::GetDialIdFromName(const std::string &dialName) { @@ -185,6 +169,7 @@ namespace OHOS } return 0; // 如果未找到对应的表盘名称,返回0或者其他适当的默认值 } + /* 获取当前表盘Id */ uint16_t SetDialModel::GetCurrentDialID() { @@ -292,57 +277,22 @@ namespace OHOS void SetDialModel::LoadAllDial() { dialInfoList.clear(); + // 加载自定义表盘 LoadAllDialFromRam(); size_t dialSize = dialInfoList.size(); + // 加载默认表盘 LoadAllDialFromDefult(); + // 加载离线表盘 LoadAllDialFromFs(); - /* 只排序离线表盘 */ + /* 排序离线表盘 */ std::sort(dialInfoList.begin() + dialSize, dialInfoList.end(), [](const SetDialInfo &f, const SetDialInfo &n) { return f.dialName < n.dialName; }); + // 表盘Id以及表盘map打印 char dialId[128]; GetAllDialIDs(dialId); PrintRegisteredDials(registeredDials); } - /*加载自定义表盘*/ - void SetDialModel::LoadAllDialFromRam() - { - for (uint8_t i = DIAL_CLOCK; i < DIAL_MAX; i++) - { - // 获取表盘信息 - const DialInfo *info = MainModel::GetInstance().GetDialInfo((DialId)i); - if (info == nullptr) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LoadAllDialFromRam: Dial info for ID %u is nullptr", i); - continue; - } - - // 初始化表盘信息 - SetDialInfo dialInfo{0}; - dialInfo.dialFlag = 0; - dialInfo.id = i; - dialInfo.dialName = info->dialName; - dialInfo.imageFullName = info->dialImg; - - // 加载图像资源 - ImageInfo *imageInfo = ImageCacheManager::GetInstance().LoadSingleRes(info->dialImg, false); - if (imageInfo == nullptr) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LoadAllDialFromRam load image %s failed", info->dialImg.c_str()); - continue; - } - - // 设置图像信息 - dialInfo.preImageInfo = imageInfo; - - // 添加到表盘列表 - dialInfoList.push_back(dialInfo); - - // 日志输出 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Parsed Dial: ID: %u, Name: %s, Image: %s", - dialInfo.id, dialInfo.dialName.c_str(), dialInfo.imageFullName.c_str()); - } - } /*加载离线表盘*/ void SetDialModel::LoadAllDialFromFs() { @@ -393,7 +343,7 @@ namespace OHOS closedir(dirp); return; } - /*通过表盘名称解析表盘*/ + /*通过表盘名称解析表盘 [离线表盘]*/ int32_t SetDialModel::ParseDialHeader(int type, const std::string &dialFileName, SetDialInfo &dialInfo) { std::string dialFullName; @@ -410,7 +360,7 @@ namespace OHOS FILE *fp = fopen(dialFullName.c_str(), "rb"); if (fp == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ParseDialHeader cannot open file: %s", + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ParseDialHeader cannot open file: %s", dialFullName.c_str()); return -1; } @@ -418,19 +368,19 @@ namespace OHOS bool ret = DialBinParser::GetInstance()->GetDialPreviewInfo(fp, &preInfo); if (!ret) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetDialPreviewInfo %s fail", + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetDialPreviewInfo %s fail", dialFullName.c_str()); return -1; } - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ParseDialHeader dialFullName: %s", + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ParseDialHeader dialFullName: %s", dialFullName.c_str()); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ParseDialHeader dialName: %s", + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ParseDialHeader dialName: %s", preInfo.dialName); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ParseDialHeader description: %s", + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ParseDialHeader description: %s", preInfo.description); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ParseDialHeader previewImgId: %u", + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ParseDialHeader previewImgId: %u", preInfo.imgId); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ParseDialHeader imageOffset: %u", + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ParseDialHeader imageOffset: %u", preInfo.offset); ImageInfo *info = ImageCacheManager::GetInstance().LoadOneInMultiRes( preInfo.imgId, dialFullName, fp, false, preInfo.offset); @@ -447,30 +397,11 @@ namespace OHOS dialInfo.description = preInfo.description; dialInfo.preImageInfo = info; -#if 0 - // 需要判断表盘是否存在 不存在->新表盘注册 - if (GetDialIdFromName(dialInfo.dialName) == 0) - { - // 找到已注册表盘中最大的ID - uint16_t maxDialId = 103; - for (auto it = registeredDials.begin(); it != registeredDials.end(); ++it) - { - if (it->first >= maxDialId && it->first != DEFAULT_DIAL_ID_1 && it->first != DEFAULT_DIAL_ID_2) - { - maxDialId = it->first; - } - } - // 分配新的表盘ID为最大ID加1 - uint16_t newDialId = maxDialId + 1; - // 注册表盘,将表盘ID和表盘文件名添加到 registeredDials 中 - RegisterDial(newDialId, (dialInfo.dialName).c_str()); - } -#endif fclose(fp); return 0; } - /*设置表盘*/ + /*设置当前表盘*/ void SetDialModel::SaveDialSetting(uint8_t pageIndex) { if (pageIndex >= dialInfoList.size()) @@ -485,6 +416,8 @@ namespace OHOS diagSetting.dialId = info.id; diagSetting.dialFullName = info.dialFullName; currentDialID = GetDialIdFromName(info.dialName); // 更新表盘Id + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "info.dialName %s info.id %d ", info.dialName.c_str(), info.id); MainModel::GetInstance().AddDialSetting(diagSetting, currentDialID); } @@ -526,10 +459,89 @@ namespace OHOS return 0; } /* --------------------------------- 自定义表盘配置 -------------------------------- */ + /*加载自定义表盘*/ + void SetDialModel::LoadAllDialFromRam() + { + for (uint8_t i = DIAL_CLOCK; i < DIAL_MAX; i++) + { + // 获取表盘列表 读取自定义表盘配置 + const DialInfo *info = MainModel::GetInstance().GetDialInfo((DialId)i); + if (info == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadAllDialFromRam: Dial info for ID %u is nullptr", i); + continue; + } + + // 处理自定义配置文件 + if (i != DIAL_CLOCK) + { + std::string customFilePath = GetSaveDir(i) + "/" + std::to_string(i) + ".bin"; + if (!CheckFileExists(customFilePath)) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Custom config file does not exist for ID: %u, filename: %s", i, customFilePath.c_str()); + continue; + } + } + + // 初始化表盘信息 + SetDialInfo dialInfo; + dialInfo.dialFlag = 0; + dialInfo.id = i; + dialInfo.dialName = info->dialName; + dialInfo.imageFullName = info->dialImg; + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Processing Dial ID %u: Name: %s", i, dialInfo.dialName.c_str()); + + // 加载图像资源 + ImageInfo *imageInfo = ImageCacheManager::GetInstance().LoadSingleRes(info->dialImg, false); + if (imageInfo == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadAllDialFromRam load image %s failed", info->dialImg); + continue; + } + + // 设置图像信息 + dialInfo.preImageInfo = imageInfo; + + // 添加到表盘列表 + dialInfoList.push_back(dialInfo); + + // 注册到map + // RegisterDial(dialInfo.id, dialInfo.dialName.c_str()); + + // 日志输出 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Parsed Dial: ID: %u, Name: %s, Image: %s", + dialInfo.id, dialInfo.dialName.c_str(), dialInfo.imageFullName.c_str()); + } + } + + // 检查文件是否存在的辅助函数 + bool SetDialModel::CheckFileExists(const std::string &filePath) + { + std::ifstream file(filePath); + return file.is_open(); + } + // 测试表盘配置写文件 + void SetDialModel::TestDialConfig() + { + DialLayout dialconfig; + + /*设置表盘参数*/ + dialconfig.dialId = 1; + dialconfig.batteryDisplay = 1; + dialconfig.timeDisplay = 0; + dialconfig.colorTypeSet = 5; + + if (!saveDialConfig(dialconfig)) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to save dial config"); + } + } // 保存自定义表盘配置到文件 bool SetDialModel::saveDialConfig(const DialLayout &layout) { - std::string filename = APP_CUSTOM_DIAL_PATH + std::to_string(layout.dialId) + ".bin"; + + std::string filename = GetSaveDir(layout.dialId) + "/" + std::to_string(layout.dialId) + ".bin"; // 创建或打开文件 std::ofstream configFile(filename, std::ios::binary | std::ios::out | std::ios::trunc); @@ -558,7 +570,7 @@ namespace OHOS */ bool SetDialModel::loadDialConfig(int Id, DialLayout &layout) { - std::string filename = APP_CUSTOM_DIAL_PATH + std::to_string(Id) + ".bin"; + std::string filename = std::string(APP_CUSTOM_DIAL_PATH) + "/" + std::to_string(Id) + ".bin"; // 打开文件 std::ifstream configFile(filename, std::ios::binary); @@ -605,14 +617,14 @@ namespace OHOS } else if (info.st_mode & S_IFDIR) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Directory already exists: %s", path.c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Directory already exists: %s", path.c_str()); } } /* 获取存储文件夹 Id(0~4)通过ID返回对应的文件夹路径 - 0 + 0 {已经被用} 1 2 3 @@ -621,19 +633,40 @@ namespace OHOS std::string SetDialModel::GetSaveDir(int Id) { // 首先检查Id是否在0~4的范围内 - if (Id < 0 || Id > 4) + if (Id <= 0 || Id > 4) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: Id must be between 0 and 4."); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: Id must be between 1 and 4."); return ""; // 或者返回一个空字符串 } // 检查 APP_CUSTOM_DIAL_PATH 是否存在 CreateDirectoryIfNotExists(APP_CUSTOM_DIAL_PATH); - std::string folderPath = std::string(APP_CUSTOM_DIAL_PATH) + "/" + std::to_string(Id); // 修复这一行 - CreateDirectoryIfNotExists(folderPath); // 确保目录存在 + std::string folderPath = std::string(APP_CUSTOM_DIAL_PATH) + "/" + std::to_string(Id); + CreateDirectoryIfNotExists(folderPath); // 确保目录存在 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Directory is %s", folderPath.c_str()); return folderPath; // 返回目录路径 } + /*获取自定义表盘名*/ + std::string SetDialModel::GetCustomName(int Id) + { + // 首先检查Id是否在0~4的范围内 + if (Id <= 0 || Id > 4) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: Id must be between 1 and 4."); + return ""; // 或者返回一个空字符串 + } + + // 获取表盘列表 读取自定义表盘配置 + const DialInfo *info = MainModel::GetInstance().GetDialInfo((DialId)Id); + + if (info == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadAllDialFromRam: Dial info for ID %u is nullptr", Id); + return ""; + } + + return (info->dialName); + } } diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialView.cpp b/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialView.cpp index 3fd875e3d..81f72f900 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialView.cpp @@ -88,7 +88,9 @@ namespace OHOS std::vector &dialInfo = presenter_->GetDialInfo(); for (auto iter : dialInfo) { - bool succ = rollerView_.AddItem(iter.dialName.c_str(), iter.preImageInfo); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::SetUpRollerView %s", + iter.dialName.c_str()); + bool succ = rollerView_.AddItem(iter.dialName, iter.preImageInfo); rollerItemNum_ += succ ? 1 : 0; } float scalerCoef = 0.55; @@ -103,23 +105,10 @@ namespace OHOS label_.SetPosition(127, 50, 200, 50); label_.SetTextColor(Color::White()); label_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - - if (dialInfo[lastIndex_].dialFlag) - { - // 切换表盘[表盘名称设置{多国语言需要配置xml里面的表盘描述}] - label_.SetText(dialInfo[lastIndex_].description.c_str()); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetText dialName %s", - dialInfo[lastIndex_].description.c_str()); - } - else - { - label_.SetText(dialInfo[lastIndex_].dialName.c_str()); - } - + label_.SetText(dialInfo[lastIndex_].dialName.c_str()); label_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); container_->Add(&label_); } - void SetDialView::OnSetUpView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::OnSetUpView"); -- 2.17.1