表盘:增加 日期星期 数据类型
authorluozheng <1732036298@qq.com>
Sun, 3 Nov 2024 09:41:34 +0000 (17:41 +0800)
committerluozheng <1732036298@qq.com>
Sun, 3 Nov 2024 09:41:34 +0000 (17:41 +0800)
code/sdk/application/wearable/fd230app/CMakeLists.txt
code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialDataBase.h
code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialModelDateWeekMDStr.h [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelDateWeekMDStr.cpp [new file with mode: 0644]

index aca3437..1c3a994 100644 (file)
@@ -183,6 +183,7 @@ set(SOURCES
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/DialModelSecondMapper.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/DialModelPowerMapper.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/DialModelPowerStr.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/DialModelDateWeekMDStr.cpp
     #exception handling
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/heart_blood/CheckAbnormalView.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/heart_blood/CheckAbnormalPresenter.cpp
index 3f16aba..3674aa8 100644 (file)
@@ -1,5 +1,3 @@
-
-
 #ifndef DIAL_DATA_BASE_H
 #define DIAL_DATA_BASE_H
 
@@ -49,8 +47,9 @@ enum class DialDataType {
   DATA_TYPE_DATE_STR,           // 日期(string)
   DATA_TYPE_WEATHER_STR,        // 天气(string)
   DATA_TYPE_TIMESTR_STR,        // 时间(string)
-  DATA_TYPE_DATE_WEEK_STR,      // 日期星期(string)
+  DATA_TYPE_DATE_WEEK_STR,      // 日期(年月日)星期(string)
   DATA_TYPE_POWER_STR,          // 电量(string)
+  DATA_TYPE_DATE_WEEK_MD_STR,   // 星期(月日)和日期(string)
 
   DATA_TYPE_MAX = 0x7fff, // 数据类型的最大值
 };
diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialModelDateWeekMDStr.h b/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialModelDateWeekMDStr.h
new file mode 100644 (file)
index 0000000..d664ba4
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-11-03 16:53:17
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-11-03 17:11:53
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialModelDateWeekMDStr.h
+ */
+
+#ifndef DIAL_MODEL_DateWeekMDStr_H
+#define DIAL_MODEL_DateWeekMDStr_H
+
+#include "DialBaseModel.h"
+#include <cstdint>
+#include <string>
+#include <vector>
+
+namespace OHOS
+{
+    class DialModelDateWeekMDStr : public DialBaseModel
+    {
+    public:
+        DialModelDateWeekMDStr() {}
+        virtual ~DialModelDateWeekMDStr() {}
+        static DialModelDateWeekMDStr *GetInstance()
+        {
+            static DialModelDateWeekMDStr instance;
+            return &instance;
+        }
+        bool GetDialTextData(DialDataType &type, std::string *&out,int16_t &strNum) override;
+        void UpdateDateWeekStr(const std::string *&dialDateWeekMDStr);
+
+    private:
+        std::string dateweekmdstr;
+    };
+} // namespace OHOS
+#endif
\ No newline at end of file
diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelDateWeekMDStr.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelDateWeekMDStr.cpp
new file mode 100644 (file)
index 0000000..8f83d94
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-11-03 16:47:34
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-11-03 17:01:37
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelDateWeekMDStr.cpp
+ */
+#include "main/include/dial/DialModelDateWeekMDStr.h"
+#include "main/include/dial/RegisterDialModel.h"
+#include "sys/time.h"
+#include "wearable_log.h"
+#include <chrono>
+#include <ctime>
+#include <iomanip>
+#include <sstream>
+#include <string>
+#include <time.h>
+
+namespace OHOS
+{
+    REGIST_DIAL_MODULE(DialDataType::DATA_TYPE_DATE_WEEK_MD_STR, OHOS::DialModelDateWeekMDStr::GetInstance());
+
+    // Cnweekdays 是一个包含周字符串的数组
+    constexpr const char *Cnweekdays[] = {"周天", "周一", "周二", "周三",
+                                          "周四", "周五", "周六"};
+
+    /*获取当前日期和星期信息 */
+
+    // 获取表盘文本数据(日期和星期信息)
+    bool DialModelDateWeekMDStr::GetDialTextData(DialDataType &type, std::string *&out, int16_t &strNum)
+    {
+        (void)type;
+        struct tm local_time = {0};
+        time_t seconds = time(nullptr);
+
+        // 获取本地时间
+        if (localtime_r(&seconds, &local_time) == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "get localtime error!");
+            return false;
+        }
+
+        // 使用ostringstream构建日期字符串
+        std::ostringstream oss;
+        oss << std::setw(2)
+            << std::setfill('0') << (local_time.tm_mon + 1) << "月"
+            << std::setw(2)
+            << std::setfill('0') << local_time.tm_mday << "日";
+
+        // 获取星期
+        dateweekmdstr = oss.str() + " " + Cnweekdays[local_time.tm_wday];
+
+        out = &dateweekmdstr;
+        strNum = 1;
+
+        return true;
+    }
+
+    void DialModelDateWeekMDStr::UpdateDateWeekStr(const std::string *&dialDateWeekMDStr)
+    {
+        dateweekmdstr.clear();
+        dateweekmdstr = *dialDateWeekMDStr; // 更新字符串
+        if (onChangeListener_ != nullptr)
+        {
+            onChangeListener_->OnDialTextDataUpdate(DialDataType::DATA_TYPE_DATE_WEEK_MD_STR, &dateweekmdstr, dateweekmdstr.size());
+        }
+    }
+} // namespace OHOS
\ No newline at end of file