同步下滑界面时间更新
authorCaisking <3449750381@qq.com>
Sat, 20 Jan 2024 10:14:18 +0000 (18:14 +0800)
committerCaisking <3449750381@qq.com>
Sat, 20 Jan 2024 10:14:18 +0000 (18:14 +0800)
code/sdk/application/wearable/nativeapp/nativeui/clock/include/MainClockView.h
code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp
code/sdk/application/wearable/nativeapp/nativeui/dial/include/Digital_clockView.h
code/sdk/application/wearable/nativeapp/nativeui/dial/src/Digital_clockView.cpp
code/sdk/application/wearable/nativeapp/nativeui/main/include/PullUpDownView.h
code/sdk/application/wearable/nativeapp/nativeui/main/src/PullUpDownView.cpp

index b43fe89..700bf75 100755 (executable)
@@ -119,8 +119,8 @@ public:
             //printf("bat check stamp %u xts_testing %u,xts_flag %u\r\n", RunTime_, xts_testing,xts_flag);
         }
 
-        char* progress1ForeImageSrc = nullptr;
-        char* progress1BackImageSrc = nullptr;
+        const char* progress1ForeImageSrc = nullptr;
+        const char* progress1BackImageSrc = nullptr;
         if (value <= 10) {
             progress1ForeImageSrc = "/user/res/Battery/Battery_Limit.bin";
         } else if (value <= 20) {
index cb1e4b5..415fae2 100755 (executable)
@@ -492,7 +492,7 @@ bool MainClockView::InitSweepClock(void)
     progress->SetForegroundStyle(STYLE_TEXT_COLOR, 0xff000000);
     progress->SetForegroundStyle(STYLE_LINE_COLOR, 0xff000000);
     progress->SetForegroundStyle(STYLE_LINE_WIDTH, 0);
-    char* progress1ForeImageSrc = "/user/res/Battery/Battery_Nomoal.bin";
+    const char* progress1ForeImageSrc = "/user/res/Battery/Battery_Nomoal.bin";
     char * progress1BackImageSrc = nullptr;
     progress->SetImage(progress1ForeImageSrc, progress1BackImageSrc);
 
index 9b861e8..d9beaf1 100644 (file)
@@ -99,7 +99,7 @@ namespace OHOS
             clock_gettime(CLOCK_MONOTONIC, &Systime);
             int SystemTime = Systime.tv_sec;
             printf("--getSystemTime::%d--\n", SystemTime);
-            clock_settime(CLOCK_MONOTONIC, &pTM);
+            //clock_settime(CLOCK_MONOTONIC, &pTM);
 #endif
             // 获取系统时间
             time(&seconds);
@@ -155,8 +155,8 @@ namespace OHOS
             //printf("value:%d\n", value);
             //根据电池电量值选择相应的进度条前景图片
 #endif
-            char *progress1ForeImageSrc = nullptr;
-            char *progress1BackImageSrc = nullptr;
+            const char *progress1ForeImageSrc = nullptr;
+            const char *progress1BackImageSrc = nullptr;
             if (value <= 10)
             {
                 progress1ForeImageSrc = "/user/res/Battery/Battery_Limit.bin"; // 低电量图片路径
index 528659b..85936f9 100644 (file)
@@ -615,8 +615,8 @@ namespace OHOS
         progress->SetForegroundStyle(STYLE_BACKGROUND_COLOR, 0xff2195F6);
         progress->SetForegroundStyle(STYLE_TEXT_COLOR, 0xff000000);
         progress->SetForegroundStyle(STYLE_LINE_COLOR, 0xff45A5FF);
-        char *progress1ForeImageSrc = "/user/res/Battery/Battery_Nomoal.bin";
-        char *progress1BackImageSrc = nullptr;
+        const char *progress1ForeImageSrc = "/user/res/Battery/Battery_Nomoal.bin";
+        const char *progress1BackImageSrc = nullptr;
         progress->SetImage(progress1ForeImageSrc, progress1BackImageSrc);
         // Add to rootView
         Add(progress);
index 04925d4..e0f4a29 100755 (executable)
@@ -1,3 +1,13 @@
+/*** 
+ * @Author: Caisking 3449750381@qq.com
+ * @Date: 2024-01-18 11:03:28
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-01-20 17:53:18
+ * @FilePath: /FD230/code/sdk/application/wearable/nativeapp/nativeui/main/include/PullUpDownView.h
+ * @Description: 
+ * @
+ * @Copyright (c) 2024 by Caisking , All Rights Reserved. 
+ */
 /*
  * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved.
  * Description: WeekStep
@@ -39,8 +49,8 @@ namespace OHOS
             uint8_t value = 0;
             value = battery_get_voltage(&voltage);
             // 根据电池电量值选择相应的进度条前景图片
-            char *progress1ForeImageSrc = nullptr;
-            char *progress1BackImageSrc = nullptr;
+            const char *progress1ForeImageSrc = nullptr;
+            const char *progress1BackImageSrc = nullptr;
             if (value <= 10)
             {
                 progress1ForeImageSrc = "/user/res/Battery/Battery_Limit.bin"; // 低电量图片路径
index 8dc8933..8d07cb7 100755 (executable)
@@ -69,6 +69,12 @@ namespace OHOS
     constexpr int16_t BLUETOOTHCONNECTSTATUS_BUTTON_X = 279;
     constexpr int16_t BLUETOOTHCONNECTSTATUS_BUTTON_Y = 369;
     /* -------------------------------------------------------------------------- */
+    std::string getWeekString(int wday)
+    {
+        std::string weekDays[] = {"星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
+        return weekDays[wday];
+    }
+    /* -------------------------------------------------------------------------- */
     static PullUpDownView *g_pPullUpDownView = nullptr;
     PullUpDownView::PullUpDownView()
     {
@@ -243,6 +249,26 @@ namespace OHOS
     /// @param  void
     void PullUpDownView::InitTimeDateWeekLabelAndConnectedStatusImage(void)
     {
+        /* -------------------------------------------------------------------------- */
+        // 将时间字段转换为字符串
+        struct tm pTM;
+        time_t seconds;
+        time(&seconds);
+        localtime_r(&seconds, &pTM);
+        // 解析
+        int hour = pTM.tm_hour;
+        int minute = pTM.tm_min;
+        std::string yearStr = std::to_string(pTM.tm_year + 1900);                                                             // 年份需要加上 1900
+        std::string monthStr = (pTM.tm_mon + 1 < 10) ? "0" + std::to_string(pTM.tm_mon + 1) : std::to_string(pTM.tm_mon + 1); // 月份是从 0 开始的,需要加上 1
+        std::string weekStr = getWeekString(pTM.tm_wday);                                                                     // 解析星期
+        // 将小时和分钟转换为字符串,并更新显示
+        std::string stringtime = (hour < 10 ? "0" : "") + std::to_string(hour) + ":" + (minute < 10 ? "0" : "") + std::to_string(minute);
+        // 连接成日期字符串
+        std::string dayStr = (pTM.tm_mday < 10) ? "0" + std::to_string(pTM.tm_mday) : std::to_string(pTM.tm_mday);
+        std::string dateStr = monthStr + "月" + dayStr + "日";
+
+        /* -------------------------------------------------------------------------- */
+
         bool ConnectedStatus = false;
         /* -------------------------------- 显示手机连接状态 -------------------------------- */
         showPhoneConnectedStatus = new UIImageView();
@@ -309,7 +335,7 @@ namespace OHOS
         showTimeLabel->SetPosition(TIME_LABEL_X, TIME_LABEL_Y);
         showTimeLabel->SetStyle(STYLE_TEXT_FONT, 50);
         showTimeLabel->SetStyle(STYLE_LINE_HEIGHT, 59);
-        showTimeLabel->SetText("23:54");
+        showTimeLabel->SetText(stringtime.c_str());
         showTimeLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
         showTimeLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
         showTimeLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 50);
@@ -323,7 +349,7 @@ namespace OHOS
         showDateLabel->SetPosition(DATE_LABEL_X, DATE_LABEL_Y);
         showDateLabel->SetStyle(STYLE_TEXT_FONT, 30);
         showDateLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
-        showDateLabel->SetText("5月16号");
+        showDateLabel->SetText(dateStr.c_str());
         showDateLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
         showDateLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
         showDateLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
@@ -337,7 +363,7 @@ namespace OHOS
         showWeekLabel->SetPosition(WEEK_LABEL_X, WEEK_LABEL_Y);
         showWeekLabel->SetStyle(STYLE_TEXT_FONT, 30);
         showWeekLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
-        showWeekLabel->SetText("星期一");
+        showWeekLabel->SetText(weekStr.c_str());
         showWeekLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
         showWeekLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
         showWeekLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);