精简运动表盘优化,但时间和日期显示不了 3020/1 3020/head
authorluozheng <1732036298@qq.com>
Tue, 6 Jan 2026 03:24:23 +0000 (11:24 +0800)
committerluozheng <1732036298@qq.com>
Tue, 6 Jan 2026 03:24:23 +0000 (11:24 +0800)
code/sdk/application/wearable/fd272/nativeapp/nativeui/main/include/dial/DialDataBase.h
code/sdk/application/wearable/fd272/nativeapp/nativeui/main/include/dial/DialDataType.h
code/sdk/application/wearable/fd272/nativeapp/nativeui/main/include/dial/DialModelTimeStr1.h [new file with mode: 0644]
code/sdk/application/wearable/fd272/nativeapp/nativeui/main/src/dial/DialDataBase.cpp
code/sdk/application/wearable/fd272/nativeapp/nativeui/main/src/dial/DialModelTimeStr1.cpp [new file with mode: 0644]
tools/dial_converter_tool/instance/208/essential_sport.xml
tools/dial_converter_tool/out/essential_sport.bin

index 44af2bd..0586094 100644 (file)
@@ -43,6 +43,7 @@ enum class DialOldDataType {
   DATA_TYPE_STEPS_GOAL_INT,   // 运动步数百分比
   DATA_TYPE_CALORIE_GOAL_INT, // 运动卡路里目标百分比
   DATA_TYPE_TIME_PERIOD_BG, // 时间段背景索引(0-3: 0-5点->0, 6-11点->1, 12-17点->2, 18-23点->3)
+  DATA_TYPE_TIME_STR,
 
 
   DATA_TYPE_MULTI_FLOAT_BASE = 0x2fff, // 多个浮点数据类型基值
index 28ced91..e91ee4d 100644 (file)
@@ -151,6 +151,7 @@ enum class DialDataType : int16_t {
     STEPS_GOAL_BOXPROGRESS,//步数目标进度条映射?
     CALORIE_GOAL_BOXPROGRESS,//卡路里目标进度条映射?
     TIME_PERIOD_BG, // 时间段背景索引(0-3: 0-5点->0, 6-11点->1, 12-17点->2, 18-23点->3)
+    TIMESTR_STR1,
 
     SWIVEL_GEAR_POSITIVE = 8190, // private data, clockwise
     SWIVEL_GEAR_NEGATIVE = 8191, // counterclockwise
diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/main/include/dial/DialModelTimeStr1.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/main/include/dial/DialModelTimeStr1.h
new file mode 100644 (file)
index 0000000..0b61a7a
--- /dev/null
@@ -0,0 +1,28 @@
+
+
+#ifndef DIAL_MODEL_TimeStr1_H
+#define DIAL_MODEL_TimeStr1_H
+
+#include "DialBaseModel.h"
+#include <cstdint>
+#include <string>
+
+namespace OHOS {
+class DialModelTimeStr1 : public DialBaseModel {
+public:
+  DialModelTimeStr1() {}
+  virtual ~DialModelTimeStr1() {}
+  static DialModelTimeStr1 *GetInstance() {
+    static DialModelTimeStr1 instance;
+    return &instance;
+  }
+  bool GetDialTextData(DialDataType &type, std::string *&out,
+                       int16_t &strNum) override;
+  void UpdateTimeStr(const std::string dialTimeStr);
+
+private:
+  struct tm tblock_;
+  std::string dialTimeStr_ = "00/00";
+};
+} // namespace OHOS
+#endif
\ No newline at end of file
index 796de17..58c8647 100644 (file)
@@ -54,6 +54,7 @@ static std::unordered_map<DialOldDataType, OHOS::DialDataType, DataTypeHash> g_d
     {DialOldDataType::DATA_TYPE_STEPS_GOAL_INT, OHOS::DialDataType::STEP_GOAL_PROGRESS},
     {DialOldDataType::DATA_TYPE_CALORIE_GOAL_INT, OHOS::DialDataType::CALORIE_RATIO},
     {DialOldDataType::DATA_TYPE_TIME_PERIOD_BG, OHOS::DialDataType::TIME_PERIOD_BG},
+    {DialOldDataType::DATA_TYPE_TIME_STR, OHOS::DialDataType::TIMESTR_STR1},
     {DialOldDataType::DATA_TYPE_WEEK_STR, OHOS::DialDataType::WEEK_STR},
     {DialOldDataType::DATA_TYPE_DATE_STR, OHOS::DialDataType::DATE_STR},
     {DialOldDataType::DATA_TYPE_WEATHER_STR, OHOS::DialDataType::WEATHER_STR},
diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/main/src/dial/DialModelTimeStr1.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/main/src/dial/DialModelTimeStr1.cpp
new file mode 100644 (file)
index 0000000..ae75c4b
--- /dev/null
@@ -0,0 +1,52 @@
+#include "main/include/dial/DialModelTimeStr1.h"
+#include "main/include/dial/RegisterDialModel.h"
+#include "custom_runtime.h"
+#include "sys/time.h"
+#include "wearable_log.h"
+#include <ctime>
+#include <iomanip>
+#include <sstream>
+#include <string>
+#include <time.h>
+#include <vector>
+
+REGIST_DIAL_MODULE(OHOS::DialDataType::TIMESTR_STR1,
+                   OHOS::DialModelTimeStr1::GetInstance());
+
+namespace OHOS {
+
+bool DialModelTimeStr1::GetDialTextData(DialDataType &type, std::string *&out,
+                                       int16_t &strNum) {
+  (void)type;
+  /*获取时间*/
+  struct timeval tv;
+  gettimeofday(&tv, NULL); // 获取当前时间
+  localtime_r(&tv.tv_sec, &tblock_);
+
+  // Use ostringstream to format the date as MM/DD (月/日) with leading zeros
+  std::ostringstream oss;
+
+  // 格式化月份(补零到2位) + / + 格式化日期(补零到2位)
+  oss << std::setw(2) << std::setfill('0') << (tblock_.tm_mon + 1) << "/"  // tm_mon从0开始,需+1
+      << std::setw(2) << std::setfill('0') << tblock_.tm_mday;
+
+  std::string dateStr = oss.str(); // 获取格式化后的日期字符串
+
+  if (!dateStr.empty()) {
+    dialTimeStr_ = dateStr;
+    out = &dialTimeStr_;
+  }
+
+  strNum = 1;
+  return true;
+}
+
+void DialModelTimeStr1::UpdateTimeStr(const std::string dialTimeStr) {
+  dialTimeStr_.clear();
+  dialTimeStr_ = dialTimeStr; // 更新字符串
+  if (onChangeListener_ != nullptr) {
+    onChangeListener_->OnDialTextDataUpdate(OHOS::DialDataType::TIMESTR_STR1,
+                                            &dialTimeStr_, 1);
+  }
+}
+} // namespace OHOS
\ No newline at end of file
index 49a1302..226a569 100644 (file)
@@ -5,7 +5,7 @@
     <!-- 时间段背景切换:0-6点、6-12点、12-18点、18-24点 -->\r
     <!-- 时间段映射:0-5点->0, 6-11点->1, 12-17点->2, 18-23点->3 -->\r
     <!-- 时间段背景切换(已实现系统端映射逻辑) -->\r
-    <!-- <option_img position="0 0" img_names="./instance/208/BACKGROUND_0_6.png,./instance/208/BACKGROUND_6_12.png,./instance/208/BACKGROUND_12_18.png,./instance/208/BACKGROUND_18_24.png" bind_data="223" period="10"></option_img> -->\r
+    <option_img position="0 0" img_names="./instance/208/BACKGROUND_0_6.png,./instance/208/BACKGROUND_6_12.png,./instance/208/BACKGROUND_12_18.png,./instance/208/BACKGROUND_18_24.png" bind_data="37" period="10"></option_img>\r
 \r
 \r
     <!-- 时针底部背景 -->\r
     <!-- 时针顶部背景 -->\r
     <static_img id="hand_top_bg" position="231 228" img_name="./instance/208/HAND_TOP.png"></static_img>\r
 \r
+    <!-- 月/日 -->\r
+    <!-- 日期弧形标签:02/08,贴近表盘外圈左下方 -->\r
+    <arc_label id="date_month_day_arc" center="-30 540" radius="233" start_angle="30" end_angle="359"\r
+            color="0xFF889199" font="HarmonyOS_Sans_SC_Regular.ttf"\r
+            text="%s" font_size="28" align="left"\r
+            bind_data="38" period="10"></arc_label>\r
+\r
+    <!-- 电量弧形标签:右下方 \"⚡80%\",贴近表盘外圈 -->\r
+    <arc_label id="battery_arc_label" center="515 515" radius="233" start_angle="310" end_angle="359"\r
+               color="0xFF889199" font="HarmonyOS_Sans_SC_Regular.ttf"\r
+               text="%s" font_size="28" align="left"\r
+               bind_data="20485" period="10"></arc_label>\r
 \r
 </dial>
\ No newline at end of file
index 56963da..8978184 100644 (file)
Binary files a/tools/dial_converter_tool/out/essential_sport.bin and b/tools/dial_converter_tool/out/essential_sport.bin differ