更新主界面下滑卡片
authorCaisking <3449750381@qq.com>
Wed, 17 Jan 2024 10:38:00 +0000 (18:38 +0800)
committerCaisking <3449750381@qq.com>
Wed, 17 Jan 2024 10:38:00 +0000 (18:38 +0800)
code/sdk/application/wearable/nativeapp/CMakeLists.txt
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
code/sdk/application/wearable/service/CMakeLists.txt
code/sdk/application/wearable/service/timeservice/CMakeLists.txt [new file with mode: 0644]
code/sdk/application/wearable/service/timeservice/include/TimeService.h [new file with mode: 0644]
code/sdk/application/wearable/service/timeservice/include/TimeServiceImpl.h [new file with mode: 0644]
code/sdk/application/wearable/service/timeservice/src/TimeServiceImpl.cpp [new file with mode: 0644]

index 4926a50..ec62c12 100755 (executable)
@@ -44,6 +44,7 @@ set(PRIVATE_HEADER
     ${UI_SAMPLE_ROOT}/components\r
     ${CMAKE_CURRENT_SOURCE_DIR}/../service/smart_voice/smart_voice_service/interfaces/innerkits/native_c/include\r
     ${CMAKE_CURRENT_SOURCE_DIR}/../service/smart_voice/voice_engine_hal/interfaces/innerkits/native_c/include\r
+    ${CMAKE_CURRENT_SOURCE_DIR}/../service/timeservice/include\r
     ${CMAKE_CURRENT_SOURCE_DIR}/../ohos_deps\r
     ${CMAKE_CURRENT_SOURCE_DIR}/../../battery\r
     ${CMAKE_CURRENT_SOURCE_DIR}/../../../drivers/drivers/driver/rtc_unified\r
index 30c447c..f0e2fbf 100644 (file)
@@ -1,12 +1,12 @@
-/*** 
+/***
  * @Author: Caisking 3449750381@qq.com
  * @Date: 2024-01-16 16:17:50
  * @LastEditors: Caisking 3449750381@qq.com
- * @LastEditTime: 2024-01-17 15:17:01
+ * @LastEditTime: 2024-01-17 16:50:57
  * @FilePath: /1.FD230/FD230/code/sdk/application/wearable/nativeapp/nativeui/dial/include/Digital_clockView.h
- * @Description: 
+ * @Description:
  * @
- * @Copyright (c) 2024 by Caisking , All Rights Reserved. 
+ * @Copyright (c) 2024 by Caisking , All Rights Reserved.
  */
 #ifndef _Digital_clock_VIEW_H
 #define _Digital_clock_VIEW_H
@@ -36,6 +36,8 @@
 #include "battery_hal.h"
 #include "cJSON.h"
 #include "sys/time.h"
+
+
 extern uint8_t battery_get_voltage(float *voltage);
 
 namespace OHOS
@@ -73,6 +75,7 @@ namespace OHOS
         static constexpr int16_t INTERVAL = 30;
         UISweepClock *sweepClock{nullptr};
     };
+    /* -------------------------------------------------------------------------- */
     class timeLableCallback : public AnimatorCallback
     {
     private:
@@ -82,10 +85,10 @@ namespace OHOS
     public:
         explicit timeLableCallback(UILabel *timeLable, std::string stringtime) : timeLable(timeLable), stringtime(stringtime) {}
         ~timeLableCallback() {}
-
         // 时钟更新的回调函数
         virtual void Callback(UIView *view) override
         {
+            /* --------------------------------- 模拟更新时间 --------------------------------- */
             // 从字符串中解析小时和分钟
             int hour = std::stoi(stringtime.substr(0, 2));
             int minute = std::stoi(stringtime.substr(3, 2));
@@ -99,8 +102,9 @@ namespace OHOS
             // 将小时和分钟转换为字符串,并更新 stringtime
             stringtime = (hour < 10 ? "0" : "") + std::to_string(hour) + ":" + (minute < 10 ? "0" : "") + std::to_string(minute);
             timeLable->SetText(stringtime.c_str());
-        }
+                    }
     };
+    /* -------------------------------------------------------------------------- */
     class myProgressCallback : public AnimatorCallback
     {
     private:
@@ -219,7 +223,7 @@ namespace OHOS
         Digital_clockView();
         virtual ~Digital_clockView();
         static Digital_clockView *GetInstance(void);
-
+        
         bool InitView();
         void DeInit();
         void setJsonFilePath(const std::string &filePath);
@@ -239,7 +243,7 @@ namespace OHOS
         void UnLoad(void) override;
 
     private:
-       
+
         UIView::OnDragListener *draglistener{nullptr};
         Digital_clockView(Digital_clockView &&) = delete;
         Digital_clockView &operator=(Digital_clockView &&) = delete;
index ac24dd2..e80240d 100644 (file)
@@ -1,3 +1,13 @@
+/*** 
+ * @Author: Caisking 3449750381@qq.com
+ * @Date: 2024-01-16 19:07:38
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-01-17 18:25:27
+ * @FilePath: /1.FD230/FD230/code/sdk/application/wearable/nativeapp/nativeui/dial/src/Digital_clockView.cpp
+ * @Description: 
+ * @
+ * @Copyright (c) 2024 by Caisking , All Rights Reserved. 
+ */
 /***
  * @Author: Caisking 3449750381@qq.com
  * @Date: 2024-01-02 11:23:34
@@ -102,6 +112,7 @@ namespace OHOS
         }
         return false;
     }
+    /* -------------------------------------------------------------------------- */
     static Digital_clockView *g_pDigital_clockView{nullptr};
     Digital_clockView::Digital_clockView()
     {
@@ -117,6 +128,7 @@ namespace OHOS
     {
         return g_pDigital_clockView;
     }
+    /* -------------------------------------------------------------------------- */
     /**
      * @description: 生成动画的资源路径数组
      * @param {char} *basePath
index c633422..e213179 100755 (executable)
 #include "components/ui_image_view.h"\r
 #include "components/ui_label.h"\r
 #include "components/ui_label_button.h"\r
+#include "components/ui_box_progress.h"\r
+#include "components/ui_image_animator.h"\r
+#include "battery_hal.h"\r
 \r
-namespace OHOS {\r
-class PullUpDownView : public UICardPage {\r
-public:\r
-    PullUpDownView();\r
-    virtual ~PullUpDownView();\r
-    static PullUpDownView *GetInstance(void);\r
-    bool InitView();\r
-    void PreLoad(void) override;\r
-    void UpdateBlueToothStatus(int status);\r
-private:\r
-    UIImageView *dropSetting{nullptr};                  //设置\r
-    UIImageView *dropLighting{nullptr};                 //亮屏\r
-    UIImageView *dropBluetooth{nullptr};                //蓝牙\r
-    UIImageView *dropSavePower{nullptr};                //省电\r
-    UIImageView *drofindPhone{nullptr};                 //找手机\r
-    UIImageView *dropIconBackground[5]{nullptr};        //放置各个icon的背景\r
-    UIImageView *showPhoneConnectedStatus{nullptr};     //显示手机连接状态\r
-    UIImageView *showEarPhoneConnectedStatus{nullptr};  //显示耳机连接状态\r
-    UIImageView *showBluetoothConnectedStatus{nullptr}; //显示蓝牙连接状态\r
-    UILabel * showTimeLabel{nullptr};                   //显示时间\r
-    UILabel * showDateLabel{nullptr};                   //显示日期\r
-    UILabel * showWeekLabel{nullptr};                   //显示星期\r
-    void InitViewImgBackGround(void);\r
-    void InitViewImg(void);\r
-    void InitTimeDateWeekLabelAndConnectedStatusImage(void);\r
-    bool viewiInitStatus{false};\r
-\r
-    UIView::OnClickListener *clickListener{nullptr};\r
-};\r
+extern uint8_t battery_get_voltage(float *voltage);\r
+\r
+namespace OHOS\r
+{\r
+    class pullProgressCallback : public AnimatorCallback\r
+    {\r
+    private:\r
+        UIBoxProgress *progress{nullptr}; // 电池进度条控件指针\r
+    public:\r
+        explicit pullProgressCallback(UIBoxProgress *progress) : progress(progress) {}\r
+        ~pullProgressCallback() {}\r
+\r
+        // 电池进度更新的回调函数\r
+        virtual void Callback(UIView *view) override\r
+        {\r
+            // 获取电池电压值\r
+            float voltage = 0.0F;\r
+            uint8_t value = 0;\r
+            value = battery_get_voltage(&voltage);\r
+            // 根据电池电量值选择相应的进度条前景图片\r
+            char *progress1ForeImageSrc = nullptr;\r
+            char *progress1BackImageSrc = nullptr;\r
+            if (value <= 10)\r
+            {\r
+                progress1ForeImageSrc = "/user/res/Battery/Battery_Limit.bin"; // 低电量图片路径\r
+            }\r
+            else if (value <= 20)\r
+            {\r
+                progress1ForeImageSrc = "/user/res/Battery/Battery_Save.bin"; // 中等电量图片路径\r
+            }\r
+            else\r
+            {\r
+                progress1ForeImageSrc = "/user/res/Battery/Battery_Nomoal.bin"; // 正常电量图片路径\r
+            }\r
+\r
+            // 设置进度条的前景和背景图片,并更新进度值\r
+            progress->SetImage(progress1ForeImageSrc, progress1BackImageSrc);\r
+            progress->SetValue(value); // 更新界面\r
+        }\r
+    };\r
+    class PullUpDownView : public UICardPage\r
+    {\r
+    public:\r
+        PullUpDownView();\r
+        virtual ~PullUpDownView();\r
+        static PullUpDownView *GetInstance(void);\r
+        bool InitView();\r
+        void PreLoad(void) override;\r
+        void UpdateBlueToothStatus(int status);\r
+\r
+    private:\r
+        UIImageView *dropSetting{nullptr};                  // 设置\r
+        UIImageView *dropLighting{nullptr};                 // 亮屏\r
+        UIImageView *dropBluetooth{nullptr};                // 蓝牙\r
+        UIImageView *dropSavePower{nullptr};                // 省电\r
+        UIImageView *drofindPhone{nullptr};                 // 找手机\r
+        UIImageView *dropIconBackground[5]{nullptr};        // 放置各个icon的背景\r
+        UIImageView *showPhoneConnectedStatus{nullptr};     // 显示手机连接状态\r
+        UIImageView *showEarPhoneConnectedStatus{nullptr};  // 显示耳机连接状态\r
+        UIImageView *showBluetoothConnectedStatus{nullptr}; // 显示蓝牙连接状态\r
+        UILabel *showTimeLabel{nullptr};                    // 显示时间\r
+        UILabel *showDateLabel{nullptr};                    // 显示日期\r
+        UILabel *showWeekLabel{nullptr};                    // 显示星期\r
+\r
+        UIImageView *batteryimage = nullptr;\r
+        UIBoxProgress *progress = nullptr;\r
+        AnimatorCallback *progresscallback_ = nullptr;\r
+        Animator *progressanimator_ = nullptr;\r
+\r
+        void InitViewImgBackGround(void);\r
+        void InitViewImg(void);\r
+        void InitTimeDateWeekLabelAndConnectedStatusImage(void);\r
+        bool viewiInitStatus{false};\r
+\r
+        UIView::OnClickListener *clickListener{nullptr};\r
+    };\r
 }\r
 #endif\r
index 810d473..64cf009 100755 (executable)
@@ -107,6 +107,21 @@ namespace OHOS
         showEarPhoneConnectedStatus = nullptr;\r
         delete showBluetoothConnectedStatus;\r
         showBluetoothConnectedStatus = nullptr;\r
+        /* -------------------------------------------------------------------------- */\r
+        delete progress;\r
+        progress = nullptr;\r
+        if (progresscallback_ != nullptr)\r
+        {\r
+            delete progresscallback_;\r
+            progresscallback_ = nullptr;\r
+        }\r
+        if (progressanimator_ != nullptr)\r
+        {\r
+            progressanimator_->Stop();\r
+            delete progressanimator_;\r
+            progressanimator_ = nullptr;\r
+        }\r
+        /* -------------------------------------------------------------------------- */\r
         g_pPullUpDownView = nullptr;\r
     }\r
 \r
@@ -199,7 +214,7 @@ namespace OHOS
         dropSavePower->SetResizeMode(UIImageView::CENTER);\r
         ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, dropSavePower, DROPDOWN_SAVEPOWER);\r
         dropSavePower->SetViewId(DROPDOWN_CLICK_SAVEELE); // 进入省电界面\r
-        \r
+\r
         dropSavePower->SetTouchable(true);\r
         dropSavePower->SetOnClickListener(clickListener);\r
         /* ----------------------------------- 找手机 ---------------------------------- */\r
@@ -223,7 +238,7 @@ namespace OHOS
         Add(dropSavePower);\r
         Add(drofindPhone);\r
     }\r
-    \r
+\r
     /// @brief 初始化时间,日期,星期标签和连接状态\r
     /// @param  void\r
     void PullUpDownView::InitTimeDateWeekLabelAndConnectedStatusImage(void)\r
@@ -283,7 +298,7 @@ namespace OHOS
             ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, showBluetoothConnectedStatus, DROPDOWN_BLUETOOTHDISCONNECTED);\r
         }\r
         /* --------------------------------- 电量状态显示 --------------------------------- */\r
-        \r
+\r
         /* ---------------------------------- 时间显示 ---------------------------------- */\r
         showTimeLabel = new UILabel();\r
         if (showTimeLabel == nullptr)\r
@@ -327,7 +342,47 @@ namespace OHOS
         showWeekLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
         showWeekLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);\r
         /* -------------------------------- 将组件添加到视图 -------------------------------- */\r
-        //Add(Battery);//电池的\r
+        if (batteryimage == nullptr)\r
+        {\r
+            batteryimage = new UIImageView();\r
+        }\r
+        batteryimage->SetPosition(210, 180);     // widget's left position and top position\r
+        batteryimage->Resize(48, 30);            // widget's width and height\r
+        batteryimage->SetViewId("imagebattery"); // Set style\r
+        std::string batteryimagesPath = "/user/res/Battery/Battery-E.bin";\r
+        batteryimage->SetSrc(batteryimagesPath.c_str());\r
+        Add(batteryimage);\r
+        /* -------------------------------------------------------------------------- */\r
+        float voltage = 0.0F;\r
+        uint8_t value = 0;\r
+        value = battery_get_voltage(&voltage);\r
+        // Add BoxProgress to App\r
+        if (progress == nullptr)\r
+        {\r
+            progress = new UIBoxProgress();\r
+        }\r
+        progress->SetPosition(216, 186);  // widget's left position and top position\r
+        progress->Resize(31, 19);         // widget's width and height\r
+        progress->SetViewId("progress1"); // Set style\r
+        progress->SetValidHeight(19);\r
+        progress->SetValidWidth(31);\r
+        progress->SetValue(value);\r
+        // Set BackgroundStyle\r
+        progress->SetBackgroundStyle(STYLE_BACKGROUND_OPA, 0x00);\r
+        progress->SetBackgroundStyle(STYLE_TEXT_COLOR, 0xff000000);\r
+        // Set ForegroundStyle\r
+        progress->SetForegroundStyle(STYLE_BACKGROUND_COLOR, 0xff2195F6);\r
+        progress->SetForegroundStyle(STYLE_TEXT_COLOR, 0xff000000);\r
+        progress->SetForegroundStyle(STYLE_LINE_COLOR, 0xff45A5FF);\r
+        char *progress1ForeImageSrc = "/user/res/Battery/Battery_Nomoal.bin";\r
+        char *progress1BackImageSrc = nullptr;\r
+        progress->SetImage(progress1ForeImageSrc, progress1BackImageSrc);\r
+        // Add to rootView\r
+        Add(progress);\r
+        progresscallback_ = new pullProgressCallback(progress);\r
+        progressanimator_ = new Animator(progresscallback_, progress, 10000, true);\r
+        progressanimator_->Start();\r
+        /* -------------------------------------------------------------------------- */\r
         Add(showTimeLabel);\r
         Add(showDateLabel);\r
         Add(showWeekLabel);\r
index a8260d7..dab7be7 100755 (executable)
@@ -8,3 +8,4 @@ if("CONFIG_SEA_PHS_SUPPORT" IN_LIST DEFINES)
     add_subdirectory_if_exist(smart_voice)
 endif()
 add_subdirectory_if_exist(power_manager)
+add_subdirectory_if_exist(timeservice)
diff --git a/code/sdk/application/wearable/service/timeservice/CMakeLists.txt b/code/sdk/application/wearable/service/timeservice/CMakeLists.txt
new file mode 100644 (file)
index 0000000..88742cd
--- /dev/null
@@ -0,0 +1,48 @@
+set(COMPONENT_NAME "timeservice")
+
+set(PUBLIC_HEADER
+)
+
+set(PRIVATE_HEADER
+${CMAKE_CURRENT_SOURCE_DIR}/include
+)
+
+set(SOURCES
+${CMAKE_CURRENT_SOURCE_DIR}/src/TimeServiceImpl.c
+)
+
+set(COMPONENT_PUBLIC_CCFLAGS
+)
+
+set(COMPONENT_CCFLAGS
+    -Wno-error
+    -Wno-unused-parameter
+    -fno-exceptions
+    -fno-unwind-tables
+    -fno-asynchronous-unwind-tables
+    -Wno-undef
+    -Wno-bitwise-op-parentheses
+    -Wno-shift-op-parentheses
+    -nostdlibinc
+    -nostdinc
+    -nostdlib
+    -Wno-error=unused-function
+)
+
+set(WHOLE_LINK
+    true
+)
+
+set(MAIN_COMPONENT
+    false
+)
+
+set(PUBLIC_DEFINES
+)
+
+set(PRIVATE_DEFINES
+)
+
+build_component()
+
+
diff --git a/code/sdk/application/wearable/service/timeservice/include/TimeService.h b/code/sdk/application/wearable/service/timeservice/include/TimeService.h
new file mode 100644 (file)
index 0000000..f9cfe19
--- /dev/null
@@ -0,0 +1,33 @@
+
+/***
+ * @Author: Caisking 3449750381@qq.com
+ * @Date: 2024-01-17 16:12:26
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-01-17 16:12:28
+ * @FilePath: /FD230/code/sdk/application/wearable/service/timeservice/include/TimeService.h
+ * @Description:
+ * @
+ * @Copyright (c) 2024 by Caisking , All Rights Reserved.
+ */
+#ifndef TIMESERVICE_H
+#define TIMESERVICE_H
+
+#include <string>
+#include <vector>
+
+class TimeUpdateListener
+{
+public:
+    virtual void onTimeUpdate(const std::string &updatedTime) = 0;
+    virtual ~TimeUpdateListener() {}
+};
+
+class TimeService
+{
+public:
+    virtual std::string getCurrentTime() = 0;
+    virtual void subscribeTimeUpdate(TimeUpdateListener *listener) = 0;
+    virtual ~TimeService() {}
+};
+
+#endif // TIMESERVICE_H
\ No newline at end of file
diff --git a/code/sdk/application/wearable/service/timeservice/include/TimeServiceImpl.h b/code/sdk/application/wearable/service/timeservice/include/TimeServiceImpl.h
new file mode 100644 (file)
index 0000000..da4bbeb
--- /dev/null
@@ -0,0 +1,29 @@
+/*** 
+ * @Author: Caisking 3449750381@qq.com
+ * @Date: 2024-01-17 16:12:44
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-01-17 16:23:51
+ * @FilePath: /FD230/code/sdk/application/wearable/service/timeservice/include/TimeServiceImpl.h
+ * @Description: 
+ * @
+ * @Copyright (c) 2024 by Caisking , All Rights Reserved. 
+ */
+// TimeServiceImpl.h
+#ifndef TIMESERVICEIMPL_H
+#define TIMESERVICEIMPL_H
+
+#include "TimeService.h"
+#include <thread>
+#include <chrono>
+
+class TimeServiceImpl : public TimeService {
+private:
+    std::vector<TimeUpdateListener*> listeners;
+
+public:
+    std::string getCurrentTime() override;
+    void subscribeTimeUpdate(TimeUpdateListener* listener) override;
+    void updateAndNotify();
+};
+
+#endif // TIMESERVICEIMPL_H
\ No newline at end of file
diff --git a/code/sdk/application/wearable/service/timeservice/src/TimeServiceImpl.cpp b/code/sdk/application/wearable/service/timeservice/src/TimeServiceImpl.cpp
new file mode 100644 (file)
index 0000000..98f55f0
--- /dev/null
@@ -0,0 +1,40 @@
+/***
+ * @Author: Caisking 3449750381@qq.com
+ * @Date: 2024-01-17 16:13:11
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-01-17 16:13:13
+ * @FilePath: /FD230/code/sdk/application/wearable/service/timeservice/src/TimeServiceImpl.cpp
+ * @Description:
+ * @
+ * @Copyright (c) 2024 by Caisking , All Rights Reserved.
+ */
+// TimeServiceImpl.cpp
+#include "TimeServiceImpl.h"
+#include <ctime>
+
+std::string TimeServiceImpl::getCurrentTime()
+{
+    time_t now = time(0);
+    tm *localTime = localtime(&now);
+    char buffer[80];
+    strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", localTime);
+    return std::string(buffer);
+}
+
+void TimeServiceImpl::subscribeTimeUpdate(TimeUpdateListener *listener)
+{
+    listeners.push_back(listener);
+}
+
+void TimeServiceImpl::updateAndNotify()
+{
+    while (true)
+    {
+        std::string updatedTime = getCurrentTime();
+        for (TimeUpdateListener *listener : listeners)
+        {
+            listener->onTimeUpdate(updatedTime);
+        }
+        std::this_thread::sleep_for(std::chrono::seconds(1));
+    }
+}
\ No newline at end of file