#include "animator/animator_manager.h"
#include "time.h"
#include "sys/time.h"
+#include "animator/animator.h"
+#include "common/image_cache_manager.h"
+#include <time.h>
+#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;
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<bool> stopThread;
+};
class MainClockView : public UICardPage {
public:
MainClockView();
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};
UIImageView *heartRate{nullptr};
Image *hand24Hour{nullptr};
UIImageView *weekDay{nullptr};
- UIImageView *progress{nullptr};
+ //UIImageView *progress{nullptr};
Image *bigCircle{nullptr};
Image *medCircle{nullptr};
Image *smallCircle{nullptr};
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
if (mainSweepClock == nullptr) {
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "mainSweepClock new fail");
return false;
- }
+ }
if (InitSweepClock() == false) {
return false;
}
mainSweepClock->Add(weekLabel);
mainSweepClock->Add(dataLabel);
mainSweepClock->Add(batteryLabel);
+ mainSweepClock->Add(progress);
#if 0
mainSweepClock->Add(stepLabel);
mainSweepClock->Add(heartRate);
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;
void MainClockView::ClockAnimatorStart(void)
{
if (clockAnimator != nullptr) {
+ progress1animator_->Start();
clockAnimator->Start();
}
}
{
if (clockAnimator != nullptr) {
clockAnimator->Stop();
+ progress1animator_->Stop();
}
}
UIImageView *heartRate{nullptr};
Image *hand24Hour{nullptr};
UIImageView *weekDay{nullptr};
- UIImageView *progress{nullptr};
+ //UIImageView *progress{nullptr};
Image *bigCircle{nullptr};
Image *medCircle{nullptr};
Image *smallCircle{nullptr};