增加获取所有表盘Id
authorCaisking <3449750381@qq.com>
Fri, 14 Jun 2024 10:23:06 +0000 (18:23 +0800)
committerCaisking <3449750381@qq.com>
Fri, 14 Jun 2024 10:23:06 +0000 (18:23 +0800)
code/sdk/application/wearable/fd230app/nativeui/set_dial/include/SetDialModel.h
code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialModel.cpp

index 07dfc62..171f56f 100644 (file)
@@ -1,3 +1,9 @@
+/***
+ * @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
@@ -29,6 +35,7 @@ namespace OHOS
         void UpdateDialSetting(uint16_t ID);
         uint16_t GetDialIdFromName(const std::string &dialName);
         void PrintRegisteredDials(const std::unordered_map<uint16_t, std::string> &dials);
+        int GetAllDialIDs(char *allidStr);
 
     private:
         void LoadAllDialFromRam(void);
index 15e930c..9f28c15 100644 (file)
@@ -19,6 +19,9 @@
 #include "DialBinParser.h"
 #include "custom_utils.h"
 #include "wearable_log.h"
+#include <string>
+#include <sstream>
+#include <iomanip>
 
 namespace OHOS
 {
@@ -79,6 +82,30 @@ namespace OHOS
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "currentDialID is %d,name is %s", currentDialID, registeredDials[currentDialID].c_str());
         return currentDialID;
     }
+    /* 获取所有表盘Id 每个表盘Id 2个字节 拼接为字符串 */
+    int SetDialModel::GetAllDialIDs(char *allidStr)
+    {
+        std::string allIDs;
+        for (const auto &entry : registeredDials)
+        {
+            // 格式化表盘ID为两个字节长度的字符串,不足两位则在前面补0
+            std::stringstream ss;
+            ss << std::setw(2) << std::setfill('0') << entry.first;
+            allIDs += ss.str();
+        }
+
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "allidStr is %s", allIDs.c_str());
+
+        // 将字符串拷贝到allidStr中
+        int length = allIDs.size();
+        if (length > 0)
+        {
+            strcpy(allidStr, allIDs.c_str());
+            allidStr[length] = '\0'; // 添加字符串结尾的空字符
+        }
+
+        return length;
+    }
     /* 判断表盘是否存在*/
     bool SetDialModel::IsDialInstalled(uint16_t ID)
     {
@@ -155,6 +182,9 @@ namespace OHOS
         /* 只排序离线表盘 */
         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);
     }
     /*加载自定义表盘*/
@@ -252,7 +282,7 @@ namespace OHOS
         dialInfo.dialName = preInfo.dialName;
         dialInfo.description = preInfo.description;
         dialInfo.preImageInfo = info;
-
+#if 0
         // 需要判断表盘是否存在 不存在->新表盘注册
         if (GetDialIdFromName(dialInfo.dialName) == 0)
         {
@@ -270,7 +300,7 @@ namespace OHOS
             // 注册表盘,将表盘ID和表盘文件名添加到 registeredDials 中
             RegisterDial(newDialId, (dialInfo.dialName).c_str());
         }
-
+#endif
         fclose(fp);
         return 0;
     }