From: SnickerSun Date: Wed, 3 Jan 2024 14:01:07 +0000 (+0800) Subject: 主表盘电池电量更新 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=2e0f2c411d99b92d37fc0f8434f6d6efc27a1995;p=mirrors%2FFD230.git 主表盘电池电量更新 --- diff --git a/code/sdk/application/wearable/nativeapp/nativeui/clock/include/MainClockView.h b/code/sdk/application/wearable/nativeapp/nativeui/clock/include/MainClockView.h index 8c454c524..ef477cbfc 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/clock/include/MainClockView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/clock/include/MainClockView.h @@ -29,7 +29,29 @@ #include "animator/animator_manager.h" #include "time.h" #include "sys/time.h" +#include "animator/animator.h" +#include "common/image_cache_manager.h" +#include +#include "sys/time.h" +#include "components/ui_box_progress.h" +#include "components/ui_image_view.h" +#include "components/ui_label.h" +#include "battery.h" +#include "hal_tick.h" +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif +#ifdef XTS_SUPPORT +extern uint8_t is_xts_test_done(void); +#endif +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif namespace OHOS { static constexpr int16_t SEC_TO_MILLI = 1000; @@ -64,49 +86,84 @@ namespace OHOS UISweepClock *sweepClock{nullptr}; }; - class MainClockView : public UICardPage +class ProgressCallback : public AnimatorCallback { +public: + explicit ProgressCallback(UIImageView *progress, UILabel *batterylabel) : progress(progress), batterylabel(batterylabel) {} + ~ProgressCallback() {} + virtual void Callback(UIView *view) { - public: - MainClockView(); - virtual ~MainClockView(); - static MainClockView *GetInstance(void); - bool InitView(void); - void PreLoad(void) override; - void UnLoad(void) override; - void RefreshStep(int step); - void RefreshHeartRate(int value); - void ClockAnimatorStart(void); - void ClockAnimatorStop(void); + float voltage = 0.0F; + uint8_t value = 0; + uint8_t xts_testing = 1; + uint32_t RunTime_ = HALTick::GetInstance().GetTime(); + #ifdef XTS_SUPPORT + xts_testing = is_xts_test_done(); + #endif + if (!xts_testing) { + xts_flag = 1; + value = 0; + //printf("bat check stamp %u xts_testing %u,xts_flag %u\r\n", RunTime_, xts_testing,xts_flag); + } else { + + value = battery_get_voltage(&voltage); + //printf("bat check stamp %u xts_testing %u,xts_flag %u\r\n", RunTime_, xts_testing,xts_flag); + } - private: - void InitStepValue(); - bool InitLabelView(void); - bool InitCenterCircleView(void); - bool InitHandView(void); - void InitDateTime(void); - bool InitSweepClock(void); - bool LoadClockImage(Image *view, uint32_t resId); - bool LoadClockImage(UIImageView *view, uint32_t resId); - UIImageView *curFace{nullptr}; - UILabelButton *stepLabel{nullptr}; - UIButton *button1_ = nullptr; - UILabel *batteryLabel{nullptr}; - UILabel *weekLabel{nullptr}; - UILabel *heartRateLabel{nullptr}; - ClockAnimatorCallback *callBack{nullptr}; - Animator *clockAnimator{nullptr}; - UISweepClock *mainSweepClock{nullptr}; - Image *secondHand{nullptr}; - Image *minuteHand{nullptr}; - Image *hourHand{nullptr}; - UIImageView *heartRate{nullptr}; - Image *hand24Hour{nullptr}; - UIImageView *weekDay{nullptr}; - UIImageView *progress{nullptr}; - Image *bigCircle{nullptr}; - Image *medCircle{nullptr}; - Image *smallCircle{nullptr}; - bool viewiInitStatus{false}; - }; + batterylabel->SetText((std::to_string(value) + "%").c_str()); + } + +private: + uint8_t xts_flag = 0; + UILabel *batterylabel{nullptr}; + UIImageView *progress{nullptr}; + //std::thread workerThread; + //std::atomic stopThread; +}; +class MainClockView : public UICardPage { +public: + MainClockView(); + virtual ~MainClockView(); + static MainClockView *GetInstance(void); + bool InitView(void); + void PreLoad(void) override; + void UnLoad(void) override; + void RefreshStep(int step); + void RefreshHeartRate(int value); + void ClockAnimatorStart(void); + void ClockAnimatorStop(void); +private: + void InitStepValue(); + bool InitLabelView(void); + bool InitCenterCircleView(void); + bool InitHandView(void); + void InitDateTime(void); + bool InitSweepClock(void); + bool LoadClockImage(Image *view, uint32_t resId); + bool LoadClockImage(UIImageView *view, uint32_t resId); + AnimatorCallback* progress1callback_ = nullptr; + Animator *progress1animator_ = nullptr; + UIImageView *curFace{nullptr}; + UILabelButton *stepLabel{nullptr}; + UIButton *button1_ = nullptr; + UILabel *batteryLabel{nullptr}; + UILabel *weekLabel{nullptr}; + UILabel *heartRateLabel{nullptr}; + UILabel *XTSLabel{nullptr}; + ClockAnimatorCallback *callBack{nullptr}; + Animator *clockAnimator{nullptr}; + UISweepClock *mainSweepClock{nullptr}; + Image *secondHand{nullptr}; + Image *minuteHand{nullptr}; + UILabel *dataLabel{nullptr}; + Image *hourHand{nullptr}; + UIImageView *heartRate{nullptr}; + Image *hand24Hour{nullptr}; + UIImageView *weekDay{nullptr}; + UIImageView *progress{nullptr}; + Image *bigCircle{nullptr}; + Image *medCircle{nullptr}; + Image *smallCircle{nullptr}; + bool viewiInitStatus{false}; +}; } // namespace OHOS #endif // MAIN_CLOCK_VIEW_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp index 73632dba5..7c1fccd9c 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp @@ -64,6 +64,11 @@ MainClockView::~MainClockView() delete clockAnimator; clockAnimator = nullptr; } + if(progress1animator_ != nullptr) { + progress1animator_->Stop(); + delete progress1animator_; + progress1animator_ = nullptr; + } mainSweepClock->RemoveAll(); delete curFace; curFace = nullptr; @@ -426,11 +431,14 @@ bool MainClockView::InitView(void) WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "callBack new fail"); return false; } - clockAnimator = new Animator(callBack, mainSweepClock, 0, true); + clockAnimator = new Animator(callBack, mainSweepClock, 50, true); if (clockAnimator == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "clockAnimator new fail"); return false; } + progress1callback_ = new ProgressCallback(progress,batteryLabel); + progress1animator_ = new Animator(progress1callback_,progress,5000,true); + progress1animator_->Start(); clockAnimator->Start(); SetCoverable(true); return true; @@ -468,6 +476,7 @@ void MainClockView::InitDateTime(void) void MainClockView::ClockAnimatorStart(void) { if (clockAnimator != nullptr) { + progress1animator_->Start(); clockAnimator->Start(); } } @@ -476,6 +485,7 @@ void MainClockView::ClockAnimatorStop(void) { if (clockAnimator != nullptr) { clockAnimator->Stop(); + progress1animator_->Stop(); } }