From 356b26e2a5b5e9ba9508c2e4bd9193a8f061d856 Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Tue, 19 Dec 2023 17:08:10 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E7=94=B5=E9=87=8F=E5=8A=A8?= =?utf8?q?=E6=80=81=E6=98=BE=E7=A4=BA=E4=BB=A5=E5=8F=8A=E7=99=BE=E5=88=86?= =?utf8?q?=E6=AF=94=E6=95=B0=E5=AD=97=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/clock/include/MainClockView.h | 41 +++++++++++++++++- .../nativeui/clock/src/MainClockView.cpp | 30 ++++++++++++- .../fs/user/res/Battery/Battery-E.bin | Bin 0 -> 1048 bytes .../fs/user/res/Battery/Battery_Limit.bin | Bin 0 -> 104 bytes .../fs/user/res/Battery/Battery_Nomoal.bin | Bin 0 -> 504 bytes .../fs/user/res/Battery/Battery_Save.bin | Bin 0 -> 184 bytes .../mk_fs_image/fs/user/res/Battery/Icon.bin | Bin 0 -> 360 bytes .../ui_test_clock_dial/MainClockView.h | 2 +- 8 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/Battery/Battery-E.bin create mode 100644 code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/Battery/Battery_Limit.bin create mode 100644 code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/Battery/Battery_Nomoal.bin create mode 100644 code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/Battery/Battery_Save.bin create mode 100644 code/sdk/build/config/target_config/brandy/mk_fs_image/fs/user/res/Battery/Icon.bin 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 0000000000000000000000000000000000000000..914c4976cce10dc1bd8e789ea688874c73a565f8 GIT binary patch literal 1048 zcmb_bK}Zx~6#o9%Y5gZEjRyXZhD6?iHrRCl=pZGM>;a?ckfkjm_&-elVn2p=ISw7~g?DD=G)dp20?p&n8 zCDmzJ3f*}3tnit%Eb@SNleN@Sv+bAOUn$LZyDE`K40Z|FE%9yhf;f91t~0&PQ7Y zayPeDT&uOUVXk~`_dPRyM7}aB1e6$Q0kk88{$fxc#xvTNNmzc7y zSV_y87-q~F7J4;$q~m$M(kmfB#GT5NtWm{T~2H)pn5p literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..20f4e432ca3496a83826e0bcfe1c065237608b5c GIT binary patch literal 360 zcmZQ@WMB|vkYf1H%psT&pvnLPfByal0~p^aa*x!3G6(kp0qe~y@(&o$*eU`gEPBbi~h0vaPUAZ!@ZlQfBgS> z@V-357e*6S28H04Ei6(DQV!cyZ?l2i;B5Gf=XkXO8%M!*{Ut2ZnS&S^{xgCkYAo-c zfByL=&^#uFdvXlhnGgEc)gSuL*vbTy1gl^;uzJ@j$IfmBmJh$>L0TC0{Qn=Exfo