From bc829135a60e6e6d1bf08b9c2cf89aa4e88b934a Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Tue, 23 Jul 2024 16:47:34 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E5=A4=8Dapp=E5=81=A5=E8=B5=B0=E5=BC=82?= =?utf8?q?=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativelauncher/include/UiConfig.h | 6 +-- .../nativeui/clock/include/MainClockView.h | 4 ++ .../nativeui/clock/src/MainClockView.cpp | 50 ++++++++++++++++++- .../fd230app/nativeui/main/src/MainModel.cpp | 3 +- .../nativeui/set_dial/src/SetDialModel.cpp | 44 ++++++++++------ .../training_card/src/TraingCardPresenter.cpp | 3 +- 6 files changed, 89 insertions(+), 21 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h index 78e5f7040..e8a3130f4 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h @@ -66,9 +66,9 @@ 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/constom_dial/" /*自定义表盘安装路径*/ #define APP_LIST_PATH "/user/res/applist_icon" /* ---------------------------------- 卡片管理 --------------------------------- */ static constexpr const char *CARD_CONFIG_PATH = "/user/cardconfig.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 f039f3f4a..668aaaaa4 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/clock/include/MainClockView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/clock/include/MainClockView.h @@ -96,6 +96,9 @@ namespace OHOS bool InitTimeView(TimeDisplayPosition type); // 时间 bool InitBatteryView(BatteryDisplayType type); // 电量 bool InitColor(ColorTypeSet type); // 颜色 + /*返回文件夹路径*/ + std::string GetSaveDir(int Id); + private: void InitStepValue(); bool InitLabelView(void); @@ -105,6 +108,7 @@ namespace OHOS bool InitClock(void); bool LoadClockImage(Image *view, uint32_t resId); bool LoadClockImage(UIImageView *view, uint32_t resId); + void CreateDirectoryIfNotExists(const std::string &path); /*表盘背景*/ 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 e429d0b30..00c04efc3 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/clock/src/MainClockView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/clock/src/MainClockView.cpp @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include "custom_runtime.h" #include "main/include/PullUpDownView.h" #include "battery_hal.h" @@ -36,7 +38,7 @@ std::string Cnweekdays[] = {"星期天", "星期一", "星期二", "星期三", static constexpr const char *CHAGE_BATTERY = "/user/res/Battery/Charge_Icon.bin"; static constexpr const char *WHITE_BATTERY = "/user/res/Battery/Battery-E.bin"; -static constexpr const char *BLACK_BATTERY = "/user/res/Battery/Charge_Icon.bin"; +static constexpr const char *BLACK_BATTERY = "/user/res/Battery/Battery-E.bin"; // 定义一些常量 constexpr int HOURS_IN_DAY = 24; @@ -173,6 +175,51 @@ namespace OHOS return true; // 成功读取配置 } + /* + 获取存储文件夹 + Id(0~4)通过ID返回对应的文件夹路径 + 0 + 1 + 2 + 3 + 4 + */ + /*创建文件夹*/ + void MainClockView::CreateDirectoryIfNotExists(const std::string &path) + { + struct stat info; + if (stat(path.c_str(), &info) != 0) + { + if (mkdir(path.c_str(), 0755) != 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: Could not create directory %s. Errno: %d", path.c_str(), errno); + } + else + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Created directory: %s", path.c_str()); + } + } + else if (info.st_mode & S_IFDIR) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Directory already exists: %s", path.c_str()); + } + } + /*获取文件夹路径*/ + std::string MainClockView::GetSaveDir(int Id) + { + // 首先检查Id是否在0~4的范围内 + if (Id < 0 || Id > 4) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: Id must be between 0 and 4."); + return ""; // 或者返回一个空字符串 + } + + std::string folderPath = APP_CUSTOM_DIAL_PATH + std::to_string(Id); + CreateDirectoryIfNotExists(folderPath); // 确保目录存在 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Directory is %s", folderPath.c_str()); + + return folderPath; // 返回目录路径 + } bool MainClockView::InitClock(void) { @@ -587,6 +634,7 @@ namespace OHOS color_ = color; batteryprogress->SetForegroundStyle(STYLE_BACKGROUND_COLOR, color_); } + /*刷新步数*/ void MainClockView::RefreshStep(int step) { 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 5c139194b..6788aaf4e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainModel.cpp @@ -43,7 +43,8 @@ namespace OHOS #ifdef CUSTOM_Z1 {DIAL_CLOCK, "Z1", DEFAULT_DIALPER_PATH, DEFAULT_TASK_PERIOD}, #else - {DIAL_CLOCK, "KUMI", DEFAULT_DIALPER_PATH, DEFAULT_TASK_PERIOD}, + {DIAL_CLOCK, "KUMI", DEFAULT_DIALPER_PATH, DEFAULT_TASK_PERIOD},//默认 + #endif }; 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 fa379d462..2f3c214a9 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 @@ -304,24 +304,38 @@ namespace OHOS { for (uint8_t i = DIAL_CLOCK; i < DIAL_MAX; i++) { + // 获取表盘信息 const DialInfo *info = MainModel::GetInstance().GetDialInfo((DialId)i); - if (info != nullptr) + if (info == nullptr) { - 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 (info == nullptr) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LoadAllDialFromRam loadimage %s fail", - info->dialImg); - continue; - } - dialInfo.preImageInfo = imageInfo; - dialInfoList.push_back(dialInfo); + 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()); } } /*加载离线表盘*/ diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardPresenter.cpp index b181f72ba..e6110447c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardPresenter.cpp @@ -315,7 +315,8 @@ namespace OHOS { case 0: TraingModel::GetInstance()->SetSportEvent(STR_EXERCISE_OUTDOORWALKING); - OpenSensor(ExerciseClass::FREE_TRAINING); + OpenSensor(ExerciseClass::OUTDOOR); + break; case 1: TraingModel::GetInstance()->SetSportEvent(STR_EXERCISE_OUTDOORRUNNING); OpenSensor(ExerciseClass::OUTDOOR); -- 2.17.1