主表盘电池电量更新
authorSnickerSun <snickersun@163.com>
Wed, 3 Jan 2024 14:01:07 +0000 (22:01 +0800)
committerSnickerSun <snickersun@163.com>
Wed, 3 Jan 2024 14:01:07 +0000 (22:01 +0800)
code/sdk/application/wearable/nativeapp/nativeui/clock/include/MainClockView.h
code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp

index 8c454c5..ef477cb 100755 (executable)
 #include "animator/animator_manager.h"\r
 #include "time.h"\r
 #include "sys/time.h"\r
+#include "animator/animator.h"\r
+#include "common/image_cache_manager.h"\r
+#include <time.h>\r
+#include "sys/time.h"\r
+#include "components/ui_box_progress.h"\r
+#include "components/ui_image_view.h"\r
+#include "components/ui_label.h"\r
+#include "battery.h"\r
 \r
+#include "hal_tick.h"\r
+#ifdef __cplusplus\r
+#if __cplusplus\r
+extern "C" {\r
+#endif\r
+#endif\r
+#ifdef XTS_SUPPORT\r
+extern uint8_t is_xts_test_done(void);\r
+#endif\r
+#ifdef __cplusplus\r
+#if __cplusplus\r
+}\r
+#endif\r
+#endif\r
 namespace OHOS\r
 {\r
     static constexpr int16_t SEC_TO_MILLI = 1000;\r
@@ -64,49 +86,84 @@ namespace OHOS
         UISweepClock *sweepClock{nullptr};\r
     };\r
 \r
-    class MainClockView : public UICardPage\r
+class ProgressCallback : public AnimatorCallback {\r
+public:\r
+    explicit ProgressCallback(UIImageView *progress, UILabel *batterylabel) : progress(progress), batterylabel(batterylabel) {}\r
+     ~ProgressCallback() {}\r
+    virtual void Callback(UIView *view)\r
     {\r
-    public:\r
-        MainClockView();\r
-        virtual ~MainClockView();\r
-        static MainClockView *GetInstance(void);\r
-        bool InitView(void);\r
-        void PreLoad(void) override;\r
-        void UnLoad(void) override;\r
-        void RefreshStep(int step);\r
-        void RefreshHeartRate(int value);\r
-        void ClockAnimatorStart(void);\r
-        void ClockAnimatorStop(void);\r
+        float voltage = 0.0F;\r
+        uint8_t value = 0;\r
+        uint8_t xts_testing = 1;\r
+        uint32_t RunTime_ = HALTick::GetInstance().GetTime();\r
+    #ifdef XTS_SUPPORT\r
+        xts_testing = is_xts_test_done();\r
+    #endif\r
+        if (!xts_testing) {\r
+            xts_flag = 1;\r
+            value = 0;\r
+            //printf("bat check stamp %u xts_testing %u,xts_flag %u\r\n", RunTime_, xts_testing,xts_flag);\r
+        } else {\r
+          \r
+            value = battery_get_voltage(&voltage);\r
+            //printf("bat check stamp %u xts_testing %u,xts_flag %u\r\n", RunTime_, xts_testing,xts_flag);\r
+        }\r
 \r
-    private:\r
-        void InitStepValue();\r
-        bool InitLabelView(void);\r
-        bool InitCenterCircleView(void);\r
-        bool InitHandView(void);\r
-        void InitDateTime(void);\r
-        bool InitSweepClock(void);\r
-        bool LoadClockImage(Image *view, uint32_t resId);\r
-        bool LoadClockImage(UIImageView *view, uint32_t resId);\r
-        UIImageView *curFace{nullptr};\r
-        UILabelButton *stepLabel{nullptr};\r
-        UIButton *button1_ = nullptr;\r
-        UILabel *batteryLabel{nullptr};\r
-        UILabel *weekLabel{nullptr};\r
-        UILabel *heartRateLabel{nullptr};\r
-        ClockAnimatorCallback *callBack{nullptr};\r
-        Animator *clockAnimator{nullptr};\r
-        UISweepClock *mainSweepClock{nullptr};\r
-        Image *secondHand{nullptr};\r
-        Image *minuteHand{nullptr};\r
-        Image *hourHand{nullptr};\r
-        UIImageView *heartRate{nullptr};\r
-        Image *hand24Hour{nullptr};\r
-        UIImageView *weekDay{nullptr};\r
-        UIImageView *progress{nullptr};\r
-        Image *bigCircle{nullptr};\r
-        Image *medCircle{nullptr};\r
-        Image *smallCircle{nullptr};\r
-        bool viewiInitStatus{false};\r
-    };\r
+        batterylabel->SetText((std::to_string(value) + "%").c_str()); \r
+    }\r
+    \r
+private:\r
+    uint8_t xts_flag = 0;\r
+    UILabel *batterylabel{nullptr};\r
+    UIImageView *progress{nullptr};\r
+    //std::thread workerThread;\r
+    //std::atomic<bool> stopThread;\r
+};\r
+class MainClockView : public UICardPage {\r
+public:\r
+    MainClockView();\r
+    virtual ~MainClockView();\r
+    static MainClockView *GetInstance(void);\r
+    bool InitView(void);\r
+    void PreLoad(void) override;\r
+    void UnLoad(void) override;\r
+    void RefreshStep(int step);\r
+    void RefreshHeartRate(int value);\r
+    void ClockAnimatorStart(void);\r
+    void ClockAnimatorStop(void);\r
+private:\r
+    void InitStepValue();\r
+    bool InitLabelView(void);\r
+    bool InitCenterCircleView(void);\r
+    bool InitHandView(void);\r
+    void InitDateTime(void);\r
+    bool InitSweepClock(void);\r
+    bool LoadClockImage(Image *view, uint32_t resId);\r
+    bool LoadClockImage(UIImageView *view, uint32_t resId);\r
+    AnimatorCallback* progress1callback_ = nullptr;\r
+    Animator *progress1animator_ = nullptr;\r
+    UIImageView *curFace{nullptr};\r
+    UILabelButton *stepLabel{nullptr};\r
+    UIButton *button1_ = nullptr;\r
+    UILabel *batteryLabel{nullptr};\r
+    UILabel *weekLabel{nullptr};\r
+    UILabel *heartRateLabel{nullptr};\r
+    UILabel *XTSLabel{nullptr};\r
+    ClockAnimatorCallback *callBack{nullptr};\r
+    Animator *clockAnimator{nullptr};\r
+    UISweepClock *mainSweepClock{nullptr};\r
+    Image *secondHand{nullptr};\r
+    Image *minuteHand{nullptr};\r
+    UILabel *dataLabel{nullptr};\r
+    Image *hourHand{nullptr};\r
+    UIImageView *heartRate{nullptr};\r
+    Image *hand24Hour{nullptr};\r
+    UIImageView *weekDay{nullptr};\r
+    UIImageView *progress{nullptr};\r
+    Image *bigCircle{nullptr};\r
+    Image *medCircle{nullptr};\r
+    Image *smallCircle{nullptr};\r
+    bool viewiInitStatus{false};\r
+};\r
 } // namespace OHOS\r
 #endif // MAIN_CLOCK_VIEW_H\r
index 73632db..7c1fccd 100755 (executable)
@@ -64,6 +64,11 @@ MainClockView::~MainClockView()
         delete clockAnimator;\r
         clockAnimator = nullptr;\r
     }\r
+    if(progress1animator_ != nullptr) {\r
+        progress1animator_->Stop();\r
+        delete progress1animator_;\r
+        progress1animator_ = nullptr;\r
+    }\r
     mainSweepClock->RemoveAll();\r
     delete curFace;\r
     curFace = nullptr;\r
@@ -426,11 +431,14 @@ bool MainClockView::InitView(void)
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "callBack new fail");\r
         return false;\r
     }\r
-    clockAnimator = new Animator(callBack, mainSweepClock, 0, true);\r
+    clockAnimator = new Animator(callBack, mainSweepClock, 50, true);\r
     if (clockAnimator == nullptr) {\r
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "clockAnimator new fail");\r
         return false;\r
     }\r
+    progress1callback_ = new ProgressCallback(progress,batteryLabel);\r
+    progress1animator_ = new Animator(progress1callback_,progress,5000,true);\r
+    progress1animator_->Start();\r
     clockAnimator->Start();\r
     SetCoverable(true);\r
     return true;\r
@@ -468,6 +476,7 @@ void MainClockView::InitDateTime(void)
 void MainClockView::ClockAnimatorStart(void)\r
 {\r
     if (clockAnimator != nullptr) {\r
+        progress1animator_->Start();\r
         clockAnimator->Start();\r
     }\r
 }\r
@@ -476,6 +485,7 @@ void MainClockView::ClockAnimatorStop(void)
 {\r
     if (clockAnimator != nullptr) {\r
         clockAnimator->Stop();\r
+        progress1animator_->Stop();\r
     }\r
 }\r
 \r