获取系统时间,优化缩约图
authorCaisking <3449750381@qq.com>
Fri, 19 Jan 2024 10:32:17 +0000 (18:32 +0800)
committerCaisking <3449750381@qq.com>
Fri, 19 Jan 2024 10:32:17 +0000 (18:32 +0800)
.vscode/settings.json
code/sdk/application/wearable/nativeapp/CMakeLists.txt
code/sdk/application/wearable/nativeapp/nativeui/blood/src/BloodView.cpp
code/sdk/application/wearable/nativeapp/nativeui/dial/include/DialPresenter.h
code/sdk/application/wearable/nativeapp/nativeui/dial/include/DialView.h
code/sdk/application/wearable/nativeapp/nativeui/dial/include/Digital_clockView.h
code/sdk/application/wearable/nativeapp/nativeui/dial/src/DialPresenter.cpp
code/sdk/application/wearable/nativeapp/nativeui/dial/src/DialView.cpp
code/sdk/application/wearable/nativeapp/nativeui/dial/src/Digital_clockView.cpp
code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingView.cpp
code/sdk/application/wearable/service/power_manager/src/power_display_service.c

index 07bbe7e..ae2084d 100644 (file)
@@ -4,6 +4,92 @@
         "iterator": "cpp",
         "bitset": "cpp",
         "string_view": "cpp",
-        "chrono": "cpp"
+        "chrono": "cpp",
+        "algorithm": "cpp",
+        "__bit_reference": "cpp",
+        "__bits": "cpp",
+        "__config": "cpp",
+        "__debug": "cpp",
+        "__errc": "cpp",
+        "__functional_base": "cpp",
+        "__hash_table": "cpp",
+        "__locale": "cpp",
+        "__mutex_base": "cpp",
+        "__node_handle": "cpp",
+        "__nullptr": "cpp",
+        "__split_buffer": "cpp",
+        "__string": "cpp",
+        "__threading_support": "cpp",
+        "__tree": "cpp",
+        "__tuple": "cpp",
+        "array": "cpp",
+        "atomic": "cpp",
+        "bit": "cpp",
+        "cctype": "cpp",
+        "cinttypes": "cpp",
+        "clocale": "cpp",
+        "cmath": "cpp",
+        "codecvt": "cpp",
+        "complex": "cpp",
+        "condition_variable": "cpp",
+        "csignal": "cpp",
+        "cstdarg": "cpp",
+        "cstddef": "cpp",
+        "cstdint": "cpp",
+        "cstdio": "cpp",
+        "cstdlib": "cpp",
+        "cstring": "cpp",
+        "ctime": "cpp",
+        "cwchar": "cpp",
+        "cwctype": "cpp",
+        "deque": "cpp",
+        "exception": "cpp",
+        "forward_list": "cpp",
+        "fstream": "cpp",
+        "functional": "cpp",
+        "future": "cpp",
+        "initializer_list": "cpp",
+        "iomanip": "cpp",
+        "iosfwd": "cpp",
+        "iostream": "cpp",
+        "istream": "cpp",
+        "limits": "cpp",
+        "list": "cpp",
+        "locale": "cpp",
+        "map": "cpp",
+        "memory": "cpp",
+        "mutex": "cpp",
+        "new": "cpp",
+        "numeric": "cpp",
+        "optional": "cpp",
+        "ostream": "cpp",
+        "queue": "cpp",
+        "random": "cpp",
+        "ratio": "cpp",
+        "regex": "cpp",
+        "set": "cpp",
+        "sstream": "cpp",
+        "stack": "cpp",
+        "stdexcept": "cpp",
+        "streambuf": "cpp",
+        "string": "cpp",
+        "strstream": "cpp",
+        "system_error": "cpp",
+        "tuple": "cpp",
+        "type_traits": "cpp",
+        "typeinfo": "cpp",
+        "unordered_map": "cpp",
+        "unordered_set": "cpp",
+        "utility": "cpp",
+        "vector": "cpp",
+        "*.tcc": "cpp",
+        "memory_resource": "cpp",
+        "shared_mutex": "cpp",
+        "thread": "cpp",
+        "cfenv": "cpp",
+        "filesystem": "cpp",
+        "lv_hal_tick.h": "c",
+        "*.def": "cpp",
+        "*.inc": "cpp"
     }
 }
\ No newline at end of file
index 9207ae6..76d3bbb 100755 (executable)
@@ -54,6 +54,7 @@ set(PRIVATE_HEADER
     ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/src/ui/frameworks
     ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/include/service
     ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/innerkits
+    ${ROOT_DIR}/middleware/services/gui/lvgl/src/hal
 
     ${ROOT_DIR}/open_source/openharmony/foundation/graphic/ui/interfaces/kits/events
     ${ROOT_DIR}/open_source/openharmony/foundation/graphic/ui/interfaces/kits
index 131540e..74a2360 100644 (file)
@@ -208,7 +208,7 @@ namespace OHOS
      */\r
     void BloodView::DeInit()\r
     {\r
-\r
+        RemoveAll();\r
         if (background != nullptr)\r
         {\r
             delete background;\r
index 09b2bc0..69d34ea 100644 (file)
@@ -1,3 +1,13 @@
+/*** \r
+ * @Author: Caisking 3449750381@qq.com\r
+ * @Date: 2024-01-17 19:23:30\r
+ * @LastEditors: Caisking 3449750381@qq.com\r
+ * @LastEditTime: 2024-01-19 16:02:49\r
+ * @FilePath: /FD230/code/sdk/application/wearable/nativeapp/nativeui/dial/include/DialPresenter.h\r
+ * @Description: \r
+ * @\r
+ * @Copyright (c) 2024 by Caisking , All Rights Reserved. \r
+ */\r
 #ifndef _Dial_PRESENTER_H\r
 #define _Dial_PRESENTER_H\r
 \r
@@ -23,9 +33,11 @@ namespace OHOS
         void OnStop() override;\r
 \r
         static DialPresenter *GetInstance();\r
+        int WatchFacenum = 0;\r
 \r
     private:\r
         Digital_clockView *g_pDigital_clockView{nullptr};\r
+        DialView *g_pDialView{nullptr};\r
         // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承;\r
         bool OnClick(UIView &view, const ClickEvent &event) override;\r
         bool OnDrag(UIView &view, const DragEvent &event) override;\r
index 8dd700d..8d759cd 100644 (file)
@@ -1,13 +1,14 @@
-/*** \r
+/***\r
  * @Author: Caisking 3449750381@qq.com\r
- * @Date: 2024-01-11 18:56:47\r
+ * @Date: 2024-01-17 19:23:30\r
  * @LastEditors: Caisking 3449750381@qq.com\r
- * @LastEditTime: 2024-01-12 15:12:59\r
- * @FilePath: /1.FD230/FD230/code/sdk/application/wearable/nativeapp/nativeui/dial/include/DialView.h\r
- * @Description: \r
+ * @LastEditTime: 2024-01-19 17:10:03\r
+ * @FilePath: /FD230/code/sdk/application/wearable/nativeapp/nativeui/dial/include/DialView.h\r
+ * @Description:\r
  * @\r
- * @Copyright (c) 2024 by Caisking , All Rights Reserved. \r
+ * @Copyright (c) 2024 by Caisking , All Rights Reserved.\r
  */\r
+\r
 #ifndef _Dial_VIEW_H\r
 #define _Dial_VIEW_H\r
 \r
@@ -38,24 +39,36 @@ namespace OHOS
         void OnSetUpView() override;\r
         void OnTearDownView() override;\r
         void OnStop() override;\r
-        void Init();\r
+        /* -------------------------------------------------------------------------- */\r
+        void SetLabel();\r
+        void SetImage();\r
+        int GetWatch();\r
+        void SetWatch(int setnum);\r
+        bool AddButton();\r
+        bool InitView();\r
         void DeInit();\r
-\r
-        UIView *GetView();\r
-\r
+        bool PreLoad();\r
+        /* -------------------------------------------------------------------------- */\r
     private:\r
         UIView::OnDragListener *draglistener{nullptr};\r
         DialView(DialView &&) = delete;\r
         DialView &operator=(DialView &&) = delete;\r
 \r
         UIViewGroup *container_ = nullptr;\r
+        UILabel *diallabel = nullptr;\r
+        UIImageView *dialimage = nullptr;\r
+        UIButton *choose_button = nullptr;\r
+        UIButton *left_button = nullptr;\r
+        UIButton *right_button = nullptr;\r
+        /* -------------------------------------------------------------------------- */\r
         UIScrollView *scrollView1_ = nullptr;\r
-\r
         UIButton *button5_ = nullptr;\r
         UIButton *button4_ = nullptr;\r
         UIButton *button3_ = nullptr;\r
         UIButton *button2_ = nullptr;\r
         UIButton *button1_ = nullptr;\r
+        /* -------------------------------------------------------------------------- */\r
+        bool viewiInitStatus{false};\r
     };\r
 } // namespace OHOS\r
 #endif // Dial_PRESENTER_H\r
index f7c54b0..08f91c7 100644 (file)
@@ -41,7 +41,6 @@ extern uint8_t battery_get_voltage(float *voltage);
 
 namespace OHOS
 {
-
 #define CHANGEBUTTON "changebutton" // 切换表盘按键
     class SweepClockCallback : public AnimatorCallback
     {
@@ -74,33 +73,43 @@ namespace OHOS
         static constexpr int16_t INTERVAL = 30;
         UISweepClock *sweepClock{nullptr};
     };
+    /* -------------------------------------------------------------------------- */
+
     /* -------------------------------------------------------------------------- */
     class timeLableCallback : public AnimatorCallback
     {
     private:
         UILabel *timeLable{nullptr};
         std::string stringtime;
+        struct timespec Systime;
+        struct tm pTM;
+        time_t seconds;
 
     public:
-        explicit timeLableCallback(UILabel *timeLable, std::string stringtime) : timeLable(timeLable), stringtime(stringtime) {}
+        explicit timeLableCallback(UILabel *timeLable, std::string stringtime) : timeLable(timeLable), stringtime(stringtime)
+        {
+        }
         ~timeLableCallback() {}
         // 时钟更新的回调函数
         virtual void Callback(UIView *view) override
         {
+            /* --------------------------------- 时间 --------------------------------- */
+            clock_gettime(CLOCK_MONOTONIC, &Systime);
+            int SystemTime = Systime.tv_sec;
+            printf("--getSystemTime::%d--\n", SystemTime);
             /* --------------------------------- 模拟更新时间 --------------------------------- */
-            // 从字符串中解析小时和分钟
-            int hour = std::stoi(stringtime.substr(0, 2));
-            int minute = std::stoi(stringtime.substr(3, 2));
-            // 进位处理
-            minute++;
-            if (minute >= 60)
-            {
-                minute = 0;
-                hour = (hour + 1) % 24; // 修复进位时的处理
-            }
-            // 将小时和分钟转换为字符串,并更新 stringtime
-            stringtime = (hour < 10 ? "0" : "") + std::to_string(hour) + ":" + (minute < 10 ? "0" : "") + std::to_string(minute);
+            // 获取系统时间
+            time(&seconds);
+            localtime_r(&seconds, &pTM);
+
+            // 解析小时和分钟
+            int hour = pTM.tm_hour;
+            int minute = pTM.tm_min;
+
+            // 将小时和分钟转换为字符串,并更新显示
+            std::string stringtime = (hour < 10 ? "0" : "") + std::to_string(hour) + ":" + (minute < 10 ? "0" : "") + std::to_string(minute);
             timeLable->SetText(stringtime.c_str());
+            printf("--SystemTime::%s--\n", stringtime.c_str());
         }
     };
     /* -------------------------------------------------------------------------- */
index 5e30d74..5ffd7f6 100644 (file)
@@ -11,7 +11,7 @@ namespace OHOS
 \r
     DialPresenter::DialPresenter()\r
     {\r
-\r
+        g_pDialView = new DialView();\r
         g_pDialPresenter = this;\r
     }\r
 \r
@@ -56,7 +56,7 @@ namespace OHOS
 \r
         if (event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP)\r
         {\r
-            //printf("draglistene is ok!\n");\r
+            // printf("draglistene is ok!\n");\r
             NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE);\r
         }\r
         UNUSED(view);\r
@@ -65,42 +65,71 @@ namespace OHOS
 \r
     bool DialPresenter::OnClick(UIView &view, const ClickEvent &event)\r
     {\r
+\r
         // 根据控件id查找是哪个控件触发了点击回调\r
+#if 0\r
+        /* -------------------------------------------------------------------------- */\r
+        int setnum = 0;\r
+        // 右滑按键\r
+        if (strcmp(view.GetViewId(), "button_right") == 0)\r
+        {\r
+            // 如果是第5个,则滑向第1个\r
+            setnum = WatchFacenum == 4 ? 0 : WatchFacenum + 1;\r
+            printf("--%d--\n", setnum);\r
+            WatchFacenum = setnum;\r
+            g_pDialView->SetImage();\r
+            g_pDialView->SetLabel();\r
+        }\r
+        // 左滑按键\r
+        if (strcmp(view.GetViewId(), "button_left") == 0)\r
+        {\r
+            // 如果是第1个,则滑向第5个\r
+            setnum = WatchFacenum == 0 ? 4 : WatchFacenum - 1;\r
+            printf("--%d--\n", setnum);\r
+            WatchFacenum = setnum;\r
+            g_pDialView->SetImage();\r
+            g_pDialView->SetLabel();\r
+        }\r
+#endif\r
+        /* -------------------------------------------------------------------------- */\r
+        /* -------------------------------------------------------------------------- */\r
+#if 1\r
         if (strcmp(view.GetViewId(), "kumibutton") == 0)\r
         {\r
-            //printf("join click\n");\r
+            // printf("join click\n");\r
             const std::string jsonPath = "/user/res/clocks/KUMI.json";\r
             g_pDigital_clockView->setJsonFilePath(jsonPath);\r
             NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE);\r
         }\r
         if (strcmp(view.GetViewId(), "flowerbudbutton") == 0)\r
         {\r
-            //printf("join click\n");\r
+            // printf("join click\n");\r
             const std::string jsonPath = "/user/res/clocks/flowerbud.json";\r
             g_pDigital_clockView->setJsonFilePath(jsonPath);\r
             NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE);\r
         }\r
         if (strcmp(view.GetViewId(), "maomaobutton") == 0)\r
         {\r
-            //printf("join click\n");\r
+            // printf("join click\n");\r
             const std::string jsonPath = "/user/res/clocks/maomao.json";\r
             g_pDigital_clockView->setJsonFilePath(jsonPath);\r
             NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE);\r
         }\r
         if (strcmp(view.GetViewId(), "momobutton") == 0)\r
         {\r
-            //printf("join click\n");\r
+            // printf("join click\n");\r
             const std::string jsonPath = "/user/res/clocks/momo.json";\r
             g_pDigital_clockView->setJsonFilePath(jsonPath);\r
             NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE);\r
         }\r
         if (strcmp(view.GetViewId(), "maliaobutton") == 0)\r
         {\r
-            //printf("join click\n");\r
+            // printf("join click\n");\r
             const std::string jsonPath = "/user/res/clocks/maliao.json";\r
             g_pDigital_clockView->setJsonFilePath(jsonPath);\r
             NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE);\r
         }\r
+#endif\r
         return true;\r
     }\r
 \r
index d8f36a0..8c047ff 100644 (file)
@@ -1,4 +1,13 @@
-\r
+/***\r
+ * @Author: Caisking 3449750381@qq.com\r
+ * @Date: 2024-01-17 19:23:24\r
+ * @LastEditors: Caisking 3449750381@qq.com\r
+ * @LastEditTime: 2024-01-19 10:36:39\r
+ * @FilePath: /FD230/code/sdk/application/wearable/nativeapp/nativeui/dial/src/DialView.cpp\r
+ * @Description:\r
+ * @\r
+ * @Copyright (c) 2024 by Caisking , All Rights Reserved.\r
+ */\r
 \r
 #include "dial/include/DialView.h"\r
 \r
 #include "ui_resource_image.h"\r
 #include <ui_scroll_view.h>\r
 #include "components/ui_button.h"\r
+#include <string>\r
+#include <vector>\r
 namespace OHOS\r
 {\r
+/* -------------------------------------------------------------------------- */\r
+#define REDUCED_GRAPH_PATH "/user/res/clocks/Reducedgraph/"\r
+    struct WatchFace\r
+    {\r
+        std::string thumbnailPath;\r
+        std::string name;\r
+    };\r
+    std::vector<WatchFace> watchFaces = {\r
+        {REDUCED_GRAPH_PATH "KUMI.bin", "经典表盘"},\r
+        {REDUCED_GRAPH_PATH "momo.bin", "猫猫表盘"},\r
+        {REDUCED_GRAPH_PATH "maliao.bin", "马里奥表盘"},\r
+        {REDUCED_GRAPH_PATH "maomao.bin", "Kitty表盘"},\r
+        {REDUCED_GRAPH_PATH "flowerbud.bin", "花蕾表盘"}};\r
+    /* -------------------------------------------------------------------------- */\r
+    extern int WatchFacenum;\r
     static DialView *g_pDialView{nullptr};\r
-\r
     DialView::DialView()\r
     {\r
-\r
         g_pDialView = this;\r
     }\r
 \r
@@ -25,18 +49,158 @@ namespace OHOS
 \r
     DialView *DialView::GetInstance()\r
     {\r
-\r
         return g_pDialView;\r
     }\r
-    void DialView::Init()\r
+\r
+    /***\r
+     * @description:\r
+     * @return 设置表盘名称\r
+     */\r
+    void DialView::SetLabel()\r
+    {\r
+        std::string firstName = watchFaces[DialPresenter::GetInstance()->WatchFacenum].name;\r
+        printf("--%s--\n", firstName.c_str());\r
+        // diallabel->SetText(firstName.c_str());\r
+    }\r
+\r
+    /***\r
+     * @description:\r
+     * @return 设置缩约图背景\r
+     */\r
+    void DialView::SetImage()\r
+    {\r
+        std::string firstThumbnailPath = watchFaces[DialPresenter::GetInstance()->WatchFacenum].thumbnailPath;\r
+        printf("--%s--\n", firstThumbnailPath.c_str());\r
+        const char *buttondefaultImgSrc = firstThumbnailPath.c_str();\r
+        const char *buttontriggeredImgSrc = nullptr;\r
+        // choose_button->SetImageSrc(buttondefaultImgSrc, buttontriggeredImgSrc);\r
+    }\r
+/* -------------------------------------------------------------------------- */\r
+#if 0\r
+    /***\r
+     * @description:\r
+     * @param\r
+     * @return 获取映照索引\r
+     */\r
+    int DialView::GetWatch()\r
+    {\r
+        printf("WatchFacenum:%d\n", WatchFacenum);\r
+        return WatchFacenum;\r
+    }\r
+    /***\r
+     * @description:\r
+     * @param {int} setnum\r
+     * @return 设置映照索引\r
+     */\r
+    void DialView::SetWatch(int setnum)\r
+    {\r
+        WatchFacenum = setnum;\r
+        printf("--WatchFacenum:%d\n", WatchFacenum);\r
+    }\r
+#endif\r
+    /* -------------------------------------------------------------------------- */\r
+    /***\r
+     * @description:\r
+     * @return 添加按键\r
+     */\r
+    bool DialView::AddButton()\r
+    {\r
+        // Add Button to App\r
+        if (choose_button == nullptr)\r
+        {\r
+            choose_button = new UIButton();\r
+        }\r
+        choose_button->SetPosition(103, 103);      // widget's left position and top position\r
+        choose_button->Resize(260, 260);           // widget's width and height\r
+        choose_button->SetViewId("button_choose"); // Set style\r
+        choose_button->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);\r
+        choose_button->SetStyle(STYLE_BACKGROUND_OPA, 0x00);\r
+\r
+        // Set additional property\r
+        // Set additional property\r
+        char *button1defaultImgSrc = REDUCED_GRAPH_PATH "KUMI.bin";\r
+        char *button1triggeredImgSrc = nullptr;\r
+        choose_button->SetImageSrc(button1defaultImgSrc, button1triggeredImgSrc);\r
+        choose_button->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED);\r
+\r
+        // Add the CallBack about events\r
+        UIView::OnClickListener *button1Click = static_cast<UIView::OnClickListener *>(DialPresenter::GetInstance());\r
+        choose_button->SetOnClickListener(button1Click);\r
+\r
+        // Add to rootView\r
+        container_->Add(choose_button);\r
+        choose_button->SetVisible(true);\r
+\r
+        /* -------------------------------------------------------------------------- */\r
+        // Add Button to App\r
+        if (right_button == nullptr)\r
+        {\r
+            right_button = new UIButton();\r
+        }\r
+        right_button->SetPosition(402, 208);     // widget's left position and top position\r
+        right_button->Resize(23, 50);            // widget's width and height\r
+        right_button->SetViewId("button_right"); // Set style\r
+        right_button->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);\r
+        right_button->SetStyle(STYLE_BACKGROUND_OPA, 0x00);\r
+\r
+        // Set additional property\r
+        char *button2defaultImgSrc = REDUCED_GRAPH_PATH "right_boutton.bin";\r
+        char *button2triggeredImgSrc = nullptr;\r
+        right_button->SetImageSrc(button2defaultImgSrc, button2triggeredImgSrc);\r
+        right_button->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED);\r
+\r
+        // Add the CallBack about events\r
+        UIView::OnClickListener *button2Click = static_cast<UIView::OnClickListener *>(DialPresenter::GetInstance());\r
+        right_button->SetOnClickListener(button2Click);\r
+\r
+        // Add to rootView\r
+        container_->Add(right_button);\r
+        right_button->SetVisible(true);\r
+\r
+        /* -------------------------------------------------------------------------- */\r
+\r
+        // Add Button to App\r
+        if (left_button == nullptr)\r
+        {\r
+            left_button = new UIButton();\r
+        }\r
+        left_button->SetPosition(40, 208);      // widget's left position and top position\r
+        left_button->Resize(23, 50);            // widget's width and height\r
+        left_button->SetViewId("left_boutton"); // Set style\r
+        left_button->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);\r
+        left_button->SetStyle(STYLE_BACKGROUND_OPA, 0x00);\r
+\r
+        // Set additional property\r
+        char *button3defaultImgSrc = REDUCED_GRAPH_PATH "left_boutton.bin";\r
+        char *button3triggeredImgSrc = nullptr;\r
+        left_button->SetImageSrc(button3defaultImgSrc, button3triggeredImgSrc);\r
+        left_button->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED);\r
+\r
+        // Add the CallBack about events\r
+        UIView::OnClickListener *button3Click = static_cast<UIView::OnClickListener *>(DialPresenter::GetInstance());\r
+        left_button->SetOnClickListener(button3Click);\r
+\r
+        // Add to rootView\r
+        container_->Add(left_button);\r
+        left_button->SetVisible(true);\r
+\r
+        return true;\r
+    }\r
+    /***\r
+     * @description:\r
+     * @return 初始化界面\r
+     */\r
+    bool DialView::InitView()\r
     {\r
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " void DialView::InitView");\r
         if (container_ == nullptr)\r
         {\r
             container_ = new UIViewGroup();\r
             container_->SetPosition(0, 0, 466, 466);\r
             container_->SetStyle(STYLE_BACKGROUND_OPA, 0);\r
         }\r
-\r
+        /* -------------------------------------------------------------------------- */\r
+#if 1\r
         // Add ScrollView to App\r
         if (scrollView1_ == nullptr)\r
         {\r
@@ -171,8 +335,43 @@ namespace OHOS
         // Add to scrollView1\r
         scrollView1_->Add(button1_);\r
         button1_->SetVisible(true);\r
-    }\r
+#endif\r
+        /* -------------------------------------------------------------------------- */\r
+        /* -------------------------------------------------------------------------- */\r
+#if 0\r
+        /* -------------------------------------------------------------------------- */\r
+        std::string firstThumbnailPath = watchFaces[0].thumbnailPath;\r
+        std::string firstName = watchFaces[0].name;\r
+        printf("firstThumbnailPath:%s -- firstName:%s\n", firstThumbnailPath.c_str(), firstName.c_str());\r
+        /* -------------------------------------------------------------------------- */\r
+        // Add Label to App\r
+        if (diallabel == nullptr)\r
+        {\r
+            diallabel = new UILabel();\r
+        }\r
 \r
+        diallabel->SetPosition(181, 50);    // widget's left position and top positio\r
+        diallabel->Resize(200, 60);         // widget's width and height\r
+        diallabel->SetViewId("titillabel"); // Set style\r
+        diallabel->SetStyle(STYLE_TEXT_FONT, 26);\r
+        // Set additional property\r
+        diallabel->SetText(firstName.c_str());\r
+        diallabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);\r
+        diallabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
+        diallabel->SetRollSpeed(0);\r
+        diallabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 26);\r
+        // Add to rootView\r
+        container_->Add(diallabel);\r
+        diallabel->SetVisible(true);\r
+        /* -------------------------------------------------------------------------- */\r
+        AddButton();\r
+#endif\r
+        return true;\r
+    }\r
+    /***\r
+     * @description:\r
+     * @return {*}\r
+     */\r
     void DialView::DeInit()\r
     {\r
         if (container_ != nullptr)\r
@@ -181,6 +380,32 @@ namespace OHOS
             delete container_;\r
             container_ = nullptr;\r
         }\r
+        if (diallabel != nullptr)\r
+        {\r
+            delete diallabel;\r
+            diallabel = nullptr;\r
+        }\r
+        if (dialimage != nullptr)\r
+        {\r
+            delete dialimage;\r
+            dialimage = nullptr;\r
+        }\r
+        if (choose_button != nullptr)\r
+        {\r
+            delete choose_button;\r
+            choose_button = nullptr;\r
+        }\r
+        if (left_button != nullptr)\r
+        {\r
+            delete left_button;\r
+            left_button = nullptr;\r
+        }\r
+        if (right_button != nullptr)\r
+        {\r
+            delete right_button;\r
+            right_button = nullptr;\r
+        }\r
+        /* -------------------------------------------------------------------------- */\r
         if (scrollView1_ != nullptr)\r
         {\r
             delete scrollView1_;\r
@@ -211,16 +436,30 @@ namespace OHOS
             delete button1_;\r
             button1_ = nullptr;\r
         }\r
+        /* -------------------------------------------------------------------------- */\r
     }\r
 \r
-    UIView *DialView::GetView()\r
+    /***\r
+     * @description:\r
+     * @return 加载\r
+     */\r
+    bool DialView::PreLoad()\r
     {\r
-        Init();\r
-        return container_;\r
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " void DialView::PreLoad(void)");\r
+        if (!viewiInitStatus)\r
+        {\r
+            InitView();\r
+            viewiInitStatus = true;\r
+            return true;\r
+        }\r
+        return false;\r
     }\r
 \r
     void DialView::OnStart()\r
     {\r
+        View<DialPresenter>::OnStart();\r
+        BaseView::RootView(Color::Black().full);\r
+\r
         container_ = new UIScrollView();\r
         if (container_ == nullptr)\r
         {\r
@@ -241,7 +480,11 @@ namespace OHOS
         container_->SetTouchable(true);\r
         container_->SetDraggable(true);\r
 \r
-        GetView();\r
+        if (!PreLoad())\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " void DialView::PreLoad(void) is error");\r
+        }\r
+\r
         RootView::GetInstance()->Add(container_);\r
     }\r
 \r
index dd110ea..dfd3db9 100644 (file)
 
 #define PRINT_DEBUG_INFO printf("Function: %s, Line: %d\n", __PRETTY_FUNCTION__, __LINE__);
 
-extern "C"
-{
-    int rtc_tm_to_time(struct rtc_time *tm, unsigned long *time);
-}
-
 namespace OHOS
 {
     cJSON *cjson_json = NULL;
@@ -64,8 +59,8 @@ namespace OHOS
             }
             if (sourceFile.eof())
             {
-                //printf("File overwrite success\n"); // 使用printf打印成功消息
-                return;                             // 返回true表示文件拷贝成功
+                // printf("File overwrite success\n"); // 使用printf打印成功消息
+                return; // 返回true表示文件拷贝成功
             }
             else
             {
@@ -306,23 +301,16 @@ namespace OHOS
         }
 
         /* -------------------------------------------------------------------------- */
-        struct tm local_time;
+        struct tm pTM;
         time_t seconds;
-        seconds = time(NULL);
-        if (localtime_r(&seconds, &local_time) == NULL)
-        {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Digital_clockView::Digital_clockView get localtime error!");
-            return false;
-        }
-        std::ostringstream ostrHour, ostMin;
-        ostrHour << local_time.tm_hour;
-        ostMin << local_time.tm_min;
-        std::string weekStr = ostrHour.str() + ":" + ostMin.str();
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "time = %s!", weekStr.c_str());
-        //("weekStr:%s\n", weekStr.c_str());
+        time(&seconds);
+        localtime_r(&seconds, &pTM);
+        // 解析小时和分钟
+        int hour = pTM.tm_hour;
+        int minute = pTM.tm_min;
+        // 将小时和分钟转换为字符串,并更新显示
+        stringtime = (hour < 10 ? "0" : "") + std::to_string(hour) + ":" + (minute < 10 ? "0" : "") + std::to_string(minute);
         /* -------------------------------------------------------------------------- */
-        stringtime = "20:10";
-
         // updateClockTime(stringtime);
         cJSON *digits = cJSON_GetObjectItem(cjson_json, "digits");
         std::string playformat = cJSON_GetObjectItem(digits, "playformat")->valuestring;
@@ -340,7 +328,7 @@ namespace OHOS
             addImageView(hour1_left, hour1_top, (digitspath + "point.bin").c_str(), "colon", digitsize * 2 + 10, 20);
             addImageView(hour1_left, hour1_top, (digitspath + stringtime.substr(3, 1) + ".bin").c_str(), "minute1", digitsize * 3, 0);
             addImageView(hour1_left, hour1_top, (digitspath + stringtime.substr(4, 1) + ".bin").c_str(), "minute2", digitsize * 4, 0);
-            //printf("--%s--\n", digitspath.c_str());
+            // printf("--%s--\n", digitspath.c_str());
             if (mytimeimageCallback_ == nullptr)
             {
                 mytimeimageCallback_ = new mytimeimageCallback(hour1, hour2, minute1, minute2, digitspath, stringtime);
@@ -656,7 +644,7 @@ namespace OHOS
      */
     bool Digital_clockView ::AddButton()
     {
-        
+
         // Add Button to App
         if (changebutton == nullptr)
         {
@@ -667,11 +655,11 @@ namespace OHOS
         changebutton->SetViewId(CHANGEBUTTON); // Set style
         changebutton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);
         changebutton->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
-        
+
         // Set additional property
         changebutton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED);
         changebutton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED);
-        
+
         // Add the CallBack about events
         UIView::OnLongPressListener *buttonLongPress = static_cast<UIView::OnLongPressListener *>(MainPresenterSample::GetInstance());
         changebutton->SetOnLongPressListener(buttonLongPress);
@@ -689,6 +677,9 @@ namespace OHOS
         if (loadJsonData(JosnfilePath))
         {
             std::string Dialtype = cJSON_GetObjectItem(cjson_json, "Dialtype")->valuestring;
+            /* -------------------------------------------------------------------------- */
+
+            /* -------------------------------------------------------------------------- */
             Initbackground();
             if (Dialtype == "pointer")
             {
index 5e8c734..0db223d 100644 (file)
@@ -119,7 +119,7 @@ namespace OHOS
         const char *button4defaultImgSrc = PNG_TRAING_BOUTTONMORE_IMAGE;\r
         char *button4triggeredImgSrc = nullptr;\r
         ButtonMore->SetImageSrc(button4defaultImgSrc, button4triggeredImgSrc);\r
-        //ButtonMore->SetText(traingmore.c_str());\r
+        // ButtonMore->SetText(traingmore.c_str());\r
         ButtonMore->SetLabelPosition(0, 70);\r
         ButtonMore->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20);\r
         ButtonMore->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff19ff41, UIButton::PRESSED);\r
@@ -204,7 +204,7 @@ namespace OHOS
 \r
         // Add to rootView\r
         Add(image3);\r
-        \r
+\r
         return true;\r
     }\r
 \r
@@ -229,6 +229,7 @@ namespace OHOS
 \r
     void TraingView::DeInit()\r
     {\r
+        RemoveAll();\r
         if (titleLabel != nullptr)\r
         {\r
             delete titleLabel;\r
index 5f86518..0472fdf 100755 (executable)
@@ -20,7 +20,7 @@
 #include "touch_screen_def.h"
 #include "display_state_machine.h"
 
-#define DISPLAY_AUTO_POWER_OFF_PERIOD_MS (1000 * 10)  //10秒
+#define DISPLAY_AUTO_POWER_OFF_PERIOD_MS (1000 * 120)  //120秒
 #define DISPLAY_DEFAULT_BRIGHTNESS 50
 #define POWER_DISPLAY_QUEUE_MAX_SIZE 64
 #define POWER_DISPLAY_MAX_SIZE 0x10