表盘:增加英文星期;日期 model
authorCaisking <3449750381@qq.com>
Sat, 21 Dec 2024 10:39:29 +0000 (18:39 +0800)
committerCaisking <3449750381@qq.com>
Sat, 21 Dec 2024 10:39:29 +0000 (18:39 +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/DialModelDateEnStr.h [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialModelWeekEnStr.h [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelDateEnStr.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelWeekEnStr.cpp [new file with mode: 0644]

index 2ecec40..1df338a 100644 (file)
@@ -175,9 +175,11 @@ set(SOURCES
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/DialModelDistance.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/DialModelCalorie.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/DialModelWeekStr.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/DialModelWeekEnStr.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/DialModelWeather.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/DialModelWeatherStr.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/DialModelDateStr.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/DialModelDateEnStr.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/DialModelHourTens.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/DialModelHourUnits.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/DialModelMinTens.cpp
index 3674aa8..0e1e5cb 100644 (file)
@@ -24,20 +24,22 @@ enum class DialDataType {
   DATA_TYPE_TIME_YEAR,      // 年份
   /* ------------------------------- 在下面增加新数据类型
      ------------------------------- */
-  DATA_TYPE_CHARGE,        // 充电状态
-  DATA_TYPE_DIALPATH,      // 表盘路径
-  DATA_TYPE_SPO2,          // 血氧
-  DATA_TYPE_DISTANCE,      // 运动距离
-  DATA_TYPE_WEATHER,       // 天气
-  DATA_TYPE_POWER_STANDBY, // 备用电量数据类型
-  DATA_TYPE_HOUR_TENS,     // 小时(十位)
-  DATA_TYPE_HOUR_UNITS,    // 小时(单位)
-  DATA_TYPE_MINUTE_TENS,   // 分钟(十位)
-  DATA_TYPE_MINUTE_UNITS,  // 分钟(单位)
-  DATA_TYPE_WEEK_NUM,      // 星期(数字)
-  DATA_TYPE_STEPS_GOAL,    // 运动步数目标
-  DATA_TYPE_SECOND_MAPPER, // 秒映射
-  DATA_TYPE_POWER_MAPPER,  // 电量映射
+  DATA_TYPE_CHARGE,           // 充电状态
+  DATA_TYPE_DIALPATH,         // 表盘路径
+  DATA_TYPE_SPO2,             // 血氧
+  DATA_TYPE_DISTANCE,         // 运动距离
+  DATA_TYPE_WEATHER,          // 天气
+  DATA_TYPE_POWER_STANDBY,    // 备用电量数据类型
+  DATA_TYPE_HOUR_TENS,        // 小时(十位)
+  DATA_TYPE_HOUR_UNITS,       // 小时(单位)
+  DATA_TYPE_MINUTE_TENS,      // 分钟(十位)
+  DATA_TYPE_MINUTE_UNITS,     // 分钟(单位)
+  DATA_TYPE_WEEK_NUM,         // 星期(数字)
+  DATA_TYPE_STEPS_GOAL,       // 运动步数目标
+  DATA_TYPE_SECOND_MAPPER,    // 秒映射
+  DATA_TYPE_POWER_MAPPER,     // 电量映射
+  DATA_TYPE_STEPS_GOAL_INT,   // 运动步数百分比
+  DATA_TYPE_CALORIE_GOAL_INT, // 运动卡路里目标百分比
 
   DATA_TYPE_MULTI_FLOAT_BASE = 0x2fff, // 多个浮点数据类型基值
   DATA_TYPE_HOUR_MIN,                  // 时分
@@ -50,6 +52,10 @@ enum class DialDataType {
   DATA_TYPE_DATE_WEEK_STR,      // 日期(年月日)星期(string)
   DATA_TYPE_POWER_STR,          // 电量(string)
   DATA_TYPE_DATE_WEEK_MD_STR,   // 星期(月日)和日期(string)
+  DATA_TYPE_DATE_EN_STR,        // 月份+日期 (英文)
+  DATA_TYPE_WEEK_EN_STR,        // 星期(英文)
+  DATA_TYPE_STEPS_GOAL_STR,     // 运动步数目标(string)
+  DATA_TYPE_CALORIE_GOAL_STR,   // 卡路里目标(string)
 
   DATA_TYPE_MAX = 0x7fff, // 数据类型的最大值
 };
diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialModelDateEnStr.h b/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialModelDateEnStr.h
new file mode 100644 (file)
index 0000000..75a1066
--- /dev/null
@@ -0,0 +1,28 @@
+
+
+#ifndef DIAL_MODEL_DateEnStr_H
+#define DIAL_MODEL_DateEnStr_H
+
+#include "DialBaseModel.h"
+#include <cstdint>
+#include <string>
+#include <vector>
+
+namespace OHOS {
+class DialModelDateEnStr : public DialBaseModel {
+public:
+  DialModelDateEnStr() {}
+  virtual ~DialModelDateEnStr() {}
+  static DialModelDateEnStr *GetInstance() {
+    static DialModelDateEnStr instance;
+    return &instance;
+  }
+  bool GetDialTextData(DialDataType &type, std::string *&out,
+                       int16_t &strNum) override;
+  void UpDateEnDateEnStr(const std::string *&dialDateEnStr);
+
+private:
+  std::string dialDateEnStr_;
+};
+} // namespace OHOS
+#endif
\ No newline at end of file
diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialModelWeekEnStr.h b/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialModelWeekEnStr.h
new file mode 100644 (file)
index 0000000..89c0f90
--- /dev/null
@@ -0,0 +1,34 @@
+/*** 
+ * @Date: 2024-08-03 17:35:36
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-08-07 11:50:10
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialModelWeekEnStr.h
+ */
+
+#ifndef DIAL_MODEL_WeekEnStr_H
+#define DIAL_MODEL_WeekEnStr_H
+
+#include "DialBaseModel.h"
+#include <cstdint>
+#include <string>
+
+namespace OHOS
+{
+    class DialModelWeekEnStr : public DialBaseModel
+    {
+    public:
+        DialModelWeekEnStr() {}
+        virtual ~DialModelWeekEnStr() {}
+        static DialModelWeekEnStr *GetInstance()
+        {
+            static DialModelWeekEnStr instance;
+            return &instance;
+        }
+        bool GetDialTextData(DialDataType &type, std::string *&out, int16_t &strNum) override;
+        void UpdateWeekEnStr(const std::string *&dialWeekEnStr);
+
+    private:
+        std::string dialWeekEnStr_;
+    };
+}
+#endif
\ No newline at end of file
diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelDateEnStr.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelDateEnStr.cpp
new file mode 100644 (file)
index 0000000..2320e63
--- /dev/null
@@ -0,0 +1,48 @@
+#include "DialModelDateEnStr.h"
+#include "RegisterDialModel.h"
+#include "sys/time.h"
+#include "wearable_log.h"
+#include <ctime>
+#include <sstream>
+#include <string>
+#include <time.h>
+#include <vector>
+
+REGIST_DIAL_MODULE(DialDataType::DATA_TYPE_DATE_EN_STR,
+                   OHOS::DialModelDateEnStr::GetInstance());
+
+namespace OHOS {
+
+// 12个月英文缩写
+const std::string CnMonths[] = {"JAN", "FEB", "MAR", "APR", "MAY", "JUN",
+                                "JUL", "AUG", "SEP", "OCT", "NON", "DEC"};
+
+// 获取表盘文本数据(日期相关)的函数
+bool DialModelDateEnStr::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构建日期字符串,格式为"日,英文月缩写",例如 "22,APR"
+  std::ostringstream oss;
+  oss << local_time.tm_mday << "," << CnMonths[local_time.tm_mon];
+
+  // 将构建好的字符串赋值给传出参数out指向的内存
+  dialDateEnStr_ = oss.str();
+  out = &dialDateEnStr_;
+  strNum = 1;
+
+  return true;
+}
+
+// 更新日期字符串的函数
+void DialModelDateEnStr::UpDateEnDateEnStr(const std::string *&dialDateEnStr) {}
+
+} // namespace OHOS
diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelWeekEnStr.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelWeekEnStr.cpp
new file mode 100644 (file)
index 0000000..6f04fb4
--- /dev/null
@@ -0,0 +1,49 @@
+#include "DialModelWeekEnStr.h"
+#include "RegisterDialModel.h"
+#include "sys/time.h"
+#include "wearable_log.h"
+#include <ctime>
+#include <sstream>
+#include <string>
+#include <time.h>
+
+REGIST_DIAL_MODULE(DialDataType::DATA_TYPE_WEEK_EN_STR,
+                   OHOS::DialModelWeekEnStr::GetInstance());
+namespace OHOS {
+//  CnWeekEndays 是一个包含星期字符串的数组
+// const std::string CnWeekEndays_EN[] = {"Sunday",    "Monday",   "Tuesday",
+//                                        "Wednesday", "Thursday", "Friday",
+//                                        "Saturday"};
+const std::string CnWeekEndays_EN[] = {"SUNDAY",    "MONDAY",   "TUESDAY",
+                                       "WEDNESDAY", "THURSDAY", "FRIDAY",
+                                       "SATURDAY"};
+
+bool DialModelWeekEnStr::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;
+  }
+
+  dialWeekEnStr_.clear();
+  dialWeekEnStr_ = CnWeekEndays_EN[local_time.tm_wday];
+  out = &dialWeekEnStr_;
+  strNum = 1;
+  return true;
+}
+
+void DialModelWeekEnStr::UpdateWeekEnStr(const std::string *&dialWeekEnStr) {
+  dialWeekEnStr_.clear();
+  dialWeekEnStr_ = *dialWeekEnStr; // 更新字符串
+  if (onChangeListener_ != nullptr) {
+    onChangeListener_->OnDialTextDataUpdate(DialDataType::DATA_TYPE_WEEK_EN_STR,
+                                            &dialWeekEnStr_,
+                                            dialWeekEnStr_.size());
+  }
+}
+} // namespace OHOS
\ No newline at end of file