#include "components/ui_image_view.h"
#include "components/ui_label.h"
#include "components/ui_label_button.h"
+#include "components/ui_box_progress.h"
+#include "components/ui_image_animator.h"
+#include "battery_hal.h"
-namespace OHOS {
-class PullUpDownView : public UICardPage {
-public:
- PullUpDownView();
- virtual ~PullUpDownView();
- static PullUpDownView *GetInstance(void);
- bool InitView();
- void PreLoad(void) override;
- void UpdateBlueToothStatus(int status);
-private:
- UIImageView *dropSetting{nullptr}; //设置
- UIImageView *dropLighting{nullptr}; //亮屏
- UIImageView *dropBluetooth{nullptr}; //蓝牙
- UIImageView *dropSavePower{nullptr}; //省电
- UIImageView *drofindPhone{nullptr}; //找手机
- UIImageView *dropIconBackground[5]{nullptr}; //放置各个icon的背景
- UIImageView *showPhoneConnectedStatus{nullptr}; //显示手机连接状态
- UIImageView *showEarPhoneConnectedStatus{nullptr}; //显示耳机连接状态
- UIImageView *showBluetoothConnectedStatus{nullptr}; //显示蓝牙连接状态
- UILabel * showTimeLabel{nullptr}; //显示时间
- UILabel * showDateLabel{nullptr}; //显示日期
- UILabel * showWeekLabel{nullptr}; //显示星期
- void InitViewImgBackGround(void);
- void InitViewImg(void);
- void InitTimeDateWeekLabelAndConnectedStatusImage(void);
- bool viewiInitStatus{false};
-
- UIView::OnClickListener *clickListener{nullptr};
-};
+extern uint8_t battery_get_voltage(float *voltage);
+
+namespace OHOS
+{
+ class pullProgressCallback : public AnimatorCallback
+ {
+ private:
+ UIBoxProgress *progress{nullptr}; // 电池进度条控件指针
+ public:
+ explicit pullProgressCallback(UIBoxProgress *progress) : progress(progress) {}
+ ~pullProgressCallback() {}
+
+ // 电池进度更新的回调函数
+ virtual void Callback(UIView *view) override
+ {
+ // 获取电池电压值
+ float voltage = 0.0F;
+ uint8_t value = 0;
+ value = battery_get_voltage(&voltage);
+ // 根据电池电量值选择相应的进度条前景图片
+ 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); // 更新界面
+ }
+ };
+ class PullUpDownView : public UICardPage
+ {
+ public:
+ PullUpDownView();
+ virtual ~PullUpDownView();
+ static PullUpDownView *GetInstance(void);
+ bool InitView();
+ void PreLoad(void) override;
+ void UpdateBlueToothStatus(int status);
+
+ private:
+ UIImageView *dropSetting{nullptr}; // 设置
+ UIImageView *dropLighting{nullptr}; // 亮屏
+ UIImageView *dropBluetooth{nullptr}; // 蓝牙
+ UIImageView *dropSavePower{nullptr}; // 省电
+ UIImageView *drofindPhone{nullptr}; // 找手机
+ UIImageView *dropIconBackground[5]{nullptr}; // 放置各个icon的背景
+ UIImageView *showPhoneConnectedStatus{nullptr}; // 显示手机连接状态
+ UIImageView *showEarPhoneConnectedStatus{nullptr}; // 显示耳机连接状态
+ UIImageView *showBluetoothConnectedStatus{nullptr}; // 显示蓝牙连接状态
+ UILabel *showTimeLabel{nullptr}; // 显示时间
+ UILabel *showDateLabel{nullptr}; // 显示日期
+ UILabel *showWeekLabel{nullptr}; // 显示星期
+
+ UIImageView *batteryimage = nullptr;
+ UIBoxProgress *progress = nullptr;
+ AnimatorCallback *progresscallback_ = nullptr;
+ Animator *progressanimator_ = nullptr;
+
+ void InitViewImgBackGround(void);
+ void InitViewImg(void);
+ void InitTimeDateWeekLabelAndConnectedStatusImage(void);
+ bool viewiInitStatus{false};
+
+ UIView::OnClickListener *clickListener{nullptr};
+ };
}
#endif
showEarPhoneConnectedStatus = nullptr;
delete showBluetoothConnectedStatus;
showBluetoothConnectedStatus = nullptr;
+ /* -------------------------------------------------------------------------- */
+ delete progress;
+ progress = nullptr;
+ if (progresscallback_ != nullptr)
+ {
+ delete progresscallback_;
+ progresscallback_ = nullptr;
+ }
+ if (progressanimator_ != nullptr)
+ {
+ progressanimator_->Stop();
+ delete progressanimator_;
+ progressanimator_ = nullptr;
+ }
+ /* -------------------------------------------------------------------------- */
g_pPullUpDownView = nullptr;
}
dropSavePower->SetResizeMode(UIImageView::CENTER);
ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, dropSavePower, DROPDOWN_SAVEPOWER);
dropSavePower->SetViewId(DROPDOWN_CLICK_SAVEELE); // 进入省电界面
-
+
dropSavePower->SetTouchable(true);
dropSavePower->SetOnClickListener(clickListener);
/* ----------------------------------- 找手机 ---------------------------------- */
Add(dropSavePower);
Add(drofindPhone);
}
-
+
/// @brief 初始化时间,日期,星期标签和连接状态
/// @param void
void PullUpDownView::InitTimeDateWeekLabelAndConnectedStatusImage(void)
ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, showBluetoothConnectedStatus, DROPDOWN_BLUETOOTHDISCONNECTED);
}
/* --------------------------------- 电量状态显示 --------------------------------- */
-
+
/* ---------------------------------- 时间显示 ---------------------------------- */
showTimeLabel = new UILabel();
if (showTimeLabel == nullptr)
showWeekLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
showWeekLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
/* -------------------------------- 将组件添加到视图 -------------------------------- */
- //Add(Battery);//电池的
+ if (batteryimage == nullptr)
+ {
+ batteryimage = new UIImageView();
+ }
+ batteryimage->SetPosition(210, 180); // widget's left position and top position
+ batteryimage->Resize(48, 30); // widget's width and height
+ batteryimage->SetViewId("imagebattery"); // Set style
+ std::string batteryimagesPath = "/user/res/Battery/Battery-E.bin";
+ batteryimage->SetSrc(batteryimagesPath.c_str());
+ Add(batteryimage);
+ /* -------------------------------------------------------------------------- */
+ float voltage = 0.0F;
+ uint8_t value = 0;
+ value = battery_get_voltage(&voltage);
+ // Add BoxProgress to App
+ if (progress == nullptr)
+ {
+ progress = new UIBoxProgress();
+ }
+ progress->SetPosition(216, 186); // widget's left position and top position
+ progress->Resize(31, 19); // widget's width and height
+ progress->SetViewId("progress1"); // Set style
+ progress->SetValidHeight(19);
+ progress->SetValidWidth(31);
+ progress->SetValue(value);
+ // Set BackgroundStyle
+ progress->SetBackgroundStyle(STYLE_BACKGROUND_OPA, 0x00);
+ progress->SetBackgroundStyle(STYLE_TEXT_COLOR, 0xff000000);
+ // Set ForegroundStyle
+ progress->SetForegroundStyle(STYLE_BACKGROUND_COLOR, 0xff2195F6);
+ progress->SetForegroundStyle(STYLE_TEXT_COLOR, 0xff000000);
+ progress->SetForegroundStyle(STYLE_LINE_COLOR, 0xff45A5FF);
+ char *progress1ForeImageSrc = "/user/res/Battery/Battery_Nomoal.bin";
+ char *progress1BackImageSrc = nullptr;
+ progress->SetImage(progress1ForeImageSrc, progress1BackImageSrc);
+ // Add to rootView
+ Add(progress);
+ progresscallback_ = new pullProgressCallback(progress);
+ progressanimator_ = new Animator(progresscallback_, progress, 10000, true);
+ progressanimator_->Start();
+ /* -------------------------------------------------------------------------- */
Add(showTimeLabel);
Add(showDateLabel);
Add(showWeekLabel);