修复app健走异常
authorCaisking <3449750381@qq.com>
Tue, 23 Jul 2024 08:47:34 +0000 (16:47 +0800)
committerCaisking <3449750381@qq.com>
Tue, 23 Jul 2024 08:47:34 +0000 (16:47 +0800)
code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h
code/sdk/application/wearable/fd230app/nativeui/clock/include/MainClockView.h
code/sdk/application/wearable/fd230app/nativeui/clock/src/MainClockView.cpp
code/sdk/application/wearable/fd230app/nativeui/main/src/MainModel.cpp
code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialModel.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardPresenter.cpp

index 78e5f70..e8a3130 100644 (file)
@@ -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";
index f039f3f..668aaaa 100644 (file)
@@ -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};
index e429d0b..00c04ef 100644 (file)
@@ -22,6 +22,8 @@
 #include <sstream>
 #include <iomanip>
 #include <string>
+#include <sys/stat.h>
+#include <unistd.h>
 #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)
     {
index 5c13919..6788aaf 100644 (file)
@@ -43,7 +43,8 @@ namespace OHOS
     #ifdef CUSTOM_Z1\r
         {DIAL_CLOCK, "Z1", DEFAULT_DIALPER_PATH, DEFAULT_TASK_PERIOD},\r
     #else\r
-        {DIAL_CLOCK, "KUMI", DEFAULT_DIALPER_PATH, DEFAULT_TASK_PERIOD},\r
+        {DIAL_CLOCK, "KUMI", DEFAULT_DIALPER_PATH, DEFAULT_TASK_PERIOD},//默认\r
+\r
     #endif\r
     };\r
 \r
index fa379d4..2f3c214 100644 (file)
@@ -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());
         }
     }
     /*加载离线表盘*/
index b181f72..e611044 100644 (file)
@@ -315,7 +315,8 @@ namespace OHOS
             {\r
             case 0:\r
                 TraingModel::GetInstance()->SetSportEvent(STR_EXERCISE_OUTDOORWALKING);\r
-                OpenSensor(ExerciseClass::FREE_TRAINING);\r
+                OpenSensor(ExerciseClass::OUTDOOR);\r
+                break;\r
             case 1:\r
                 TraingModel::GetInstance()->SetSportEvent(STR_EXERCISE_OUTDOORRUNNING);\r
                 OpenSensor(ExerciseClass::OUTDOOR);\r