From: Caisking <3449750381@qq.com> Date: Tue, 19 Dec 2023 09:08:10 +0000 (+0800) Subject: 增加电量动态显示以及百分比数字同步 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=356b26e2a5b5e9ba9508c2e4bd9193a8f061d856;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 b98ed65cf..0f551774a 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/clock/include/MainClockView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/clock/include/MainClockView.h @@ -29,6 +29,13 @@ #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" namespace OHOS { static constexpr int16_t SEC_TO_MILLI = 1000; @@ -60,7 +67,35 @@ public: private: UISweepClock *sweepClock{nullptr}; }; +class ProgressCallback : public AnimatorCallback { +public: + explicit ProgressCallback(UIBoxProgress *progress, UILabel *label) : progress(progress), label(label) {} + ~ProgressCallback() {} + virtual void Callback(UIView *view) + { + int value = std::rand() % 101; // 生成一个介于 0 和 100 之间的随机数 + char* progress1ForeImageSrc = nullptr; + char* progress1BackImageSrc = nullptr; + if (value <= 10) { + progress1ForeImageSrc = "/user/res/Battery/Battery_Limit.bin"; + } else if (value <= 20) { + progress1ForeImageSrc = "/user/res/Battery/Battery_Save.bin"; + } else { + progress1ForeImageSrc = "/user/res/Battery/Battery_Nomoal.bin"; + } + progress->SetImage(progress1ForeImageSrc, progress1BackImageSrc); + progress->SetValue(value); // 更新界面 + label->SetText((std::to_string(value) + "%").c_str()); // 更新百分比显示 + //for(int i=0;i<1000000000;i++){}; + } + +private: + UILabel *label{nullptr}; + UIBoxProgress *progress{nullptr}; + //std::thread workerThread; + //std::atomic stopThread; +}; class MainClockView : public UICardPage { public: MainClockView(); @@ -82,6 +117,10 @@ private: bool InitSweepClock(void); bool LoadClockImage(Image *view, uint32_t resId); bool LoadClockImage(UIImageView *view, uint32_t resId); + + UIBoxProgress* progress = nullptr; + AnimatorCallback* progress1callback_ = nullptr; + Animator *progress1animator_ = nullptr; UIImageView *curFace{nullptr}; UILabelButton *stepLabel{nullptr}; UILabel *batteryLabel{nullptr}; @@ -97,7 +136,7 @@ private: UIImageView *heartRate{nullptr}; Image *hand24Hour{nullptr}; UIImageView *weekDay{nullptr}; - UIImageView *progress{nullptr}; + //UIImageView *progress{nullptr}; Image *bigCircle{nullptr}; Image *medCircle{nullptr}; Image *smallCircle{nullptr}; 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 a02a39ced..5e163654d 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp @@ -447,6 +447,28 @@ bool MainClockView::InitSweepClock(void) weekLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); weekLabel->SetRollSpeed(0); weekLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 26); + + // Add BoxProgress to App + if (progress == nullptr) { + progress = new UIBoxProgress(); + } + progress->SetPosition(182, 58); // widget's left position and top position + progress->Resize(31, 19); // widget's width and height + progress->SetViewId("progress1");// Set style + progress->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + + // Set additional property + progress->SetValue(50); + // Set BackgroundStyle + progress->SetBackgroundStyle(STYLE_TEXT_COLOR, 0xff000000); + // Set ForegroundStyle + progress->SetForegroundStyle(STYLE_TEXT_COLOR, 0xff000000); + progress->SetForegroundStyle(STYLE_LINE_COLOR, 0xff000000); + progress->SetForegroundStyle(STYLE_LINE_WIDTH, 0); + char* progress1ForeImageSrc = "/user/res/Battery_Nomoal.bin"; + char * progress1BackImageSrc = nullptr; + progress->SetImage(progress1ForeImageSrc, progress1BackImageSrc); + /**************************************************************/ //InitLabelView(); #if 0 @@ -485,7 +507,7 @@ bool MainClockView::InitView(void) if (mainSweepClock == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "mainSweepClock new fail"); return false; - } + } if (InitSweepClock() == false) { return false; } @@ -494,6 +516,7 @@ bool MainClockView::InitView(void) mainSweepClock->Add(weekLabel); mainSweepClock->Add(dataLabel); mainSweepClock->Add(batteryLabel); + mainSweepClock->Add(progress); #if 0 mainSweepClock->Add(stepLabel); mainSweepClock->Add(heartRate); @@ -538,6 +561,9 @@ bool MainClockView::InitView(void) WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "clockAnimator new fail"); return false; } + progress1callback_ = new ProgressCallback(progress,batteryLabel); + progress1animator_ = new Animator(progress1callback_,progress,100,true); + progress1animator_->Start(); clockAnimator->Start(); SetCoverable(true); return true; @@ -579,6 +605,7 @@ void MainClockView::InitDateTime(void) void MainClockView::ClockAnimatorStart(void) { if (clockAnimator != nullptr) { + progress1animator_->Start(); clockAnimator->Start(); } } @@ -587,6 +614,7 @@ void MainClockView::ClockAnimatorStop(void) { if (clockAnimator != nullptr) { clockAnimator->Stop(); + progress1animator_->Stop(); } } diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/Battery/Battery-E.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/Battery/Battery-E.bin new file mode 100644 index 000000000..914c4976c Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/Battery/Battery-E.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/Battery/Battery_Limit.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/Battery/Battery_Limit.bin new file mode 100644 index 000000000..b37f5394f Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/Battery/Battery_Limit.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/Battery/Battery_Nomoal.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/Battery/Battery_Nomoal.bin new file mode 100644 index 000000000..ebab346c3 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/Battery/Battery_Nomoal.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/Battery/Battery_Save.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/Battery/Battery_Save.bin new file mode 100644 index 000000000..b132f4e21 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/Battery/Battery_Save.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/Battery/Icon.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/Battery/Icon.bin new file mode 100644 index 000000000..20f4e432c Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/Battery/Icon.bin differ diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_clock_dial/MainClockView.h b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_clock_dial/MainClockView.h index 27979d039..95ace9af3 100755 --- a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_clock_dial/MainClockView.h +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_clock_dial/MainClockView.h @@ -99,7 +99,7 @@ private: UIImageView *heartRate{nullptr}; Image *hand24Hour{nullptr}; UIImageView *weekDay{nullptr}; - UIImageView *progress{nullptr}; + //UIImageView *progress{nullptr}; Image *bigCircle{nullptr}; Image *medCircle{nullptr}; Image *smallCircle{nullptr};