From: Caisking <3449750381@qq.com> Date: Wed, 17 Apr 2024 03:28:24 +0000 (+0800) Subject: 优化下拉界面数据刷新,还需要接口 X-Git-Tag: release_V1.2.70_20241020_135402~1175^2~2 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=3938f3d0cc663b649f8f8f77a2b75ec6956423dd;p=mirrors%2FFD230.git 优化下拉界面数据刷新,还需要接口 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/include/MainPresenterSample.h b/code/sdk/application/wearable/fd230app/nativeui/main/include/MainPresenterSample.h index 160db5f08..451746afd 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/include/MainPresenterSample.h +++ b/code/sdk/application/wearable/fd230app/nativeui/main/include/MainPresenterSample.h @@ -47,7 +47,7 @@ namespace OHOS class MainViewSample; class MainPresenterSample : public Presenter, public ModelListenerSample, - public UIView::OnClickListener, public UISwipeView::OnSwipeListener, + public UIView::OnClickListener, public UIView::OnDragListener, public UISwipeView::OnSwipeListener, public UIView::OnLongPressListener, public UISwipeView, public CompassPresenter { public: MainPresenterSample(); @@ -60,10 +60,11 @@ public: void OnStop() override; virtual void Notify() override; bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; bool OnLongPress(UIView &view, const LongPressEvent &event) override; virtual void OnSwipe(UISwipeView &view) override; void SetPage(int8_t id); - void SetTaskPeroid(CardId cardId); + void SetTaskPeroid(CardId cardId); void setCallback(ZoomEffect *callback) { callback_ = callback; @@ -74,6 +75,8 @@ public: CardId *GetCardSettings(void); void InitDialSettings(void); DialSetting& GetDialSetting(); + void UpdataBaseData(); + private: void ProcessDataNotify(void); void SetCircleProgress(void); diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/include/MainViewSample.h b/code/sdk/application/wearable/fd230app/nativeui/main/include/MainViewSample.h index de9e751ab..6548cd88e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/include/MainViewSample.h +++ b/code/sdk/application/wearable/fd230app/nativeui/main/include/MainViewSample.h @@ -63,6 +63,8 @@ namespace OHOS void AnimatorStart(int pageIndex); void AnimatorStop(void); CardId GetHorCurrentCard() const; + PullUpDownView *GetPullUpView(); + // UICrossView::VPage GetVerCurrentCard() const; UIView *GetMainViewGroup(void) const { @@ -83,6 +85,7 @@ namespace OHOS } bool IsMainClockPage(void); + bool IsPullUpViewPage(void); void SetDragFg(bool continFg); bool GetDragFg(void); void SetPage(int16_t page); diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/include/PullUpDownView.h b/code/sdk/application/wearable/fd230app/nativeui/main/include/PullUpDownView.h index b065eda3e..513f24afd 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/include/PullUpDownView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/main/include/PullUpDownView.h @@ -1,3 +1,9 @@ +/*** + * @Date: 2024-04-16 19:15:33 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-04-16 19:56:24 + * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/main/include/PullUpDownView.h + */ /* * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. @@ -25,42 +31,6 @@ 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); - // 根据电池电量值选择相应的进度条前景图片 - const char *progress1ForeImageSrc = nullptr; - const 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: @@ -71,6 +41,14 @@ namespace OHOS void PreLoad(void) override; void UpdateBlueToothStatus(int status); void UpdateDnotDisturbStatus(int status); + bool InitBaseData(); // 初始化基础数据组件 + void RefreshData(); // 刷新数据 + + UILabel *GetTimeLabel(); + UILabel *GetDateLabel(); + UILabel *GetWeekLabel(); + UIBoxProgress *GetProgress(); + private: UIImageView *dropSetting{nullptr}; // 设置 UIImageView *dropLighting{nullptr}; // 亮屏 @@ -95,7 +73,6 @@ namespace OHOS void InitViewImg(void); void InitTimeDateWeekLabelAndConnectedStatusImage(void); bool viewiInitStatus{false}; - }; } #endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp index 570a00ea2..bcf23b296 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp @@ -25,6 +25,7 @@ #include "DialModelTime.h" #include "DialModelPower.h" #include "gfx_utils/mem_check.h" +#include "custom_utils.h" #include "traing/training_card/include/Training_CardView.h" #include "dnotdisturb/include/DnotDisturbModel.h" #if USE_OFFLINE_DIAL @@ -36,7 +37,7 @@ namespace OHOS { map g_jumpView = { - {DROPDOWN_CLICK_SETTING, VIEW_SETTING}, // 设置 + {DROPDOWN_CLICK_SETTING, VIEW_SETTING}, // 设置 {DROPDOWN_CLICK_LIGHTING, VIEW_FLASHLIGHT}, // 手电筒 {DROPDOWN_CLICK_DNOTDISTURB, VIEW_DNOTDISTURB}, // 勿扰 {DROPDOWN_CLICK_SAVEELE, VIEW_SAVEELE}, // 省电模式 @@ -137,8 +138,8 @@ namespace OHOS #endif } - //如果勿扰模式是开启状态,在下拉界面点击勿扰快捷入口会关闭勿扰模式不进入勿扰视图 - if(g_jumpView[curViewId] == VIEW_DNOTDISTURB && DnotDisturbModel::GetInstance().GetDoNotDisturbModeEnabled() == true) + // 如果勿扰模式是开启状态,在下拉界面点击勿扰快捷入口会关闭勿扰模式不进入勿扰视图 + if (g_jumpView[curViewId] == VIEW_DNOTDISTURB && DnotDisturbModel::GetInstance().GetDoNotDisturbModeEnabled() == true) { PullUpDownView::GetInstance()->UpdateDnotDisturbStatus(false); DnotDisturbModel::GetInstance().SetDoNotDisturbModeEnabled(false); @@ -170,6 +171,29 @@ namespace OHOS return true; } + bool MainPresenterSample::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(event); + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample OnDrag"); + + uint8_t cardId = view_->GetHorCurrentCard(); + if (cardId == WATCH_FACE) + { + PRINT("WATCH_FACE!\r\n"); + if (event.GetDragDirection() == DragEvent::DIRECTION_TOP_TO_BOTTOM) + { + PRINT("DIRECTION_TOP_TO_BOTTOM!\r\n"); + if (PullUpDownView::GetInstance() == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TempPresenter::OnDrag TempMainView::GetInstance() nullptr"); + return false; + } + UpdataBaseData(); + } + } + return true; + } void MainPresenterSample::SetPage(int8_t id) { if (view_ != nullptr) @@ -227,7 +251,6 @@ namespace OHOS CompassModel::GetInstance()->CloseCompassSensor(); isCompassSensorOpened_ = false; } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnSwipe OnSwipe"); return; } @@ -321,6 +344,11 @@ namespace OHOS dynamic_cast(view_->GetViewById(WATCH_FACE))->UpdateTime(); } } + //当前在下拉界面 + // if (view_->IsPullUpViewPage()) + // { + // UpdataBaseData(); + // } } void MainPresenterSample::InitCardSettings(void) @@ -347,4 +375,69 @@ namespace OHOS return MainModel::GetInstance().GetDialSetting(); } + void MainPresenterSample::UpdataBaseData() + { + PRINT("RefreshData Begin!\n"); + // 获取当前时间 + char *dateStr = (char *)malloc(9); + if (uapi_get_YYMMDD_Time(dateStr, '/') != ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get start date"); + free(dateStr); + return; + } + // 解析日期信息 + char *timeStr = (char *)malloc(9); + if (uapi_get_HHMMSS_Time(timeStr, ':', false) != ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get start time"); + free(dateStr); + free(timeStr); + return; + } + // 解析星期信息 + char *weekStr = (char *)malloc(10); + if (uapi_get_WeekStr(weekStr) != ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get week information"); + free(dateStr); + free(timeStr); + free(weekStr); + return; + } + PRINT("Read ALLData!\n"); + + // 获取电池电量信息 + float voltage = 0.0F; + uint8_t value = 0; + value = battery_get_voltage(&voltage); + // 更新电池信息 + const char *progressImages[3] = { + "/user/res/Battery/Battery_Limit.bin", // 低电量图片路径 + "/user/res/Battery/Battery_Save.bin", // 中等电量图片路径 + "/user/res/Battery/Battery_Normal.bin" // 正常电量图片路径 + }; + const char *progressImageSrc = nullptr; + for (int i = 0; i < 3; i++) + { + if (value <= (i + 1) * 10) + { + progressImageSrc = progressImages[i]; + PRINT("Update progressImageSrc!\n"); + break; + } + } + + PullUpDownView::GetInstance()->GetProgress()->SetImage(progressImageSrc, nullptr); + PullUpDownView::GetInstance()->GetProgress()->SetValue(value); + PullUpDownView::GetInstance()->GetDateLabel()->SetText(dateStr); + PullUpDownView::GetInstance()->GetTimeLabel()->SetText(timeStr); + PullUpDownView::GetInstance()->GetWeekLabel()->SetText(weekStr); + + // 释放动态分配的内存 + free(dateStr); + free(timeStr); + free(weekStr); + } + } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp index 75433d027..3827a4ec2 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp @@ -157,6 +157,13 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "mainSwipeGroup new fail"); return; } + UIView::OnDragListener *listener = static_cast(MainPresenterSample::GetInstance()); + if (listener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlarmSetWeekView:: new alarmDragListener fail"); + return; + } + mainSwipeGroup->SetOnDragListener(listener); if (callback == nullptr) { @@ -264,6 +271,12 @@ namespace OHOS messageView->SetIntercept(true); messageView->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); #endif + + } + + PullUpDownView *MainViewSample::GetPullUpView() + { + return dropDownView; } void MainViewSample::VertViewLoad(void) @@ -440,7 +453,18 @@ namespace OHOS return false; } } - + bool MainViewSample::IsPullUpViewPage(void) + { + if (mainSwipeGroup->GetCurrentPageId(0) == mainClockView->GetViewIndex() && + mainSwipeGroup->GetCurrentPageId(1) == 0) + { + return true; + } + else + { + return false; + } + } CardId MainViewSample::GetHorCurrentCard() const { CardId *cardSettings = presenter_->GetCardSettings(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/PullUpDownView.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/PullUpDownView.cpp index 54da4875f..f88b473f5 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/PullUpDownView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/PullUpDownView.cpp @@ -14,6 +14,8 @@ #include "SettingModel.h" #include "ui_resource_image.h" #include "dnotdisturb/include/DnotDisturbModel.h" +#include "custom_utils.h" + namespace OHOS { @@ -62,11 +64,11 @@ namespace OHOS constexpr int16_t TIME_LABEL_Y = 230; // 日期 - constexpr int16_t DATE_LABEL_X = 130; + constexpr int16_t DATE_LABEL_X = 110; constexpr int16_t DATE_LABEL_Y = 300; // 星期 - constexpr int16_t WEEK_LABEL_X = 265; + constexpr int16_t WEEK_LABEL_X = 295; constexpr int16_t WEEK_LABEL_Y = 300; // 手机连接状态 @@ -147,7 +149,8 @@ namespace OHOS PullUpDownView *PullUpDownView::GetInstance(void) { - return g_pPullUpDownView; + static PullUpDownView instance; + return &instance; } /// @brief 初始化icon图标背景 @@ -277,30 +280,10 @@ namespace OHOS Add(dropLine); } - /// @brief 初始化时间,日期,星期标签和连接状态 + /// @brief 连接状态 /// @param void void PullUpDownView::InitTimeDateWeekLabelAndConnectedStatusImage(void) { - /* -------------------------------------------------------------------------- */ - // 将时间字段转换为字符串 - struct tm pTM; - time_t seconds; - time(&seconds); - localtime_r(&seconds, &pTM); - // 解析 - int hour = pTM.tm_hour; - int minute = pTM.tm_min; - std::string yearStr = std::to_string(pTM.tm_year + 1900); // 年份需要加上 1900 - std::string monthStr = (pTM.tm_mon + 1 < 10) ? "0" + std::to_string(pTM.tm_mon + 1) : std::to_string(pTM.tm_mon + 1); // 月份是从 0 开始的,需要加上 1 - std::string weekStr = getWeekString(pTM.tm_wday); // 解析星期 - // 将小时和分钟转换为字符串,并更新显示 - std::string stringtime = (hour < 10 ? "0" : "") + std::to_string(hour) + ":" + (minute < 10 ? "0" : "") + std::to_string(minute); - // 连接成日期字符串 - std::string dayStr = (pTM.tm_mday < 10) ? "0" + std::to_string(pTM.tm_mday) : std::to_string(pTM.tm_mday); - std::string dateStr = monthStr + "月" + dayStr + "日"; - - /* -------------------------------------------------------------------------- */ - bool ConnectedStatus = false; /* -------------------------------- 显示手机连接状态 -------------------------------- */ showPhoneConnectedStatus = new UIImageView(); @@ -355,19 +338,25 @@ namespace OHOS { ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, showBluetoothConnectedStatus, DROPDOWN_BLUETOOTHDISCONNECTED); } - /* --------------------------------- 电量状态显示 --------------------------------- */ - + Add(showPhoneConnectedStatus); + Add(showEarPhoneConnectedStatus); + Add(showBluetoothConnectedStatus); + } + /*** + * @brief 初始化时间,日期,星期,电池 + */ + bool PullUpDownView::InitBaseData() + { /* ---------------------------------- 时间显示 ---------------------------------- */ showTimeLabel = new UILabel(); if (showTimeLabel == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showTimeLabel new fail"); - return; + return false; } showTimeLabel->SetPosition(TIME_LABEL_X, TIME_LABEL_Y); showTimeLabel->SetStyle(STYLE_TEXT_FONT, 50); showTimeLabel->SetStyle(STYLE_LINE_HEIGHT, 59); - showTimeLabel->SetText(stringtime.c_str()); showTimeLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); showTimeLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); showTimeLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 50); @@ -376,12 +365,11 @@ namespace OHOS if (showDateLabel == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showDateLabel new fail"); - return; + return false; } showDateLabel->SetPosition(DATE_LABEL_X, DATE_LABEL_Y); showDateLabel->SetStyle(STYLE_TEXT_FONT, 30); showDateLabel->SetStyle(STYLE_LINE_HEIGHT, 35); - showDateLabel->SetText(dateStr.c_str()); showDateLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); showDateLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); showDateLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); @@ -390,16 +378,15 @@ namespace OHOS if (showWeekLabel == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showWeekLabel new fail"); - return; + return false; } showWeekLabel->SetPosition(WEEK_LABEL_X, WEEK_LABEL_Y); showWeekLabel->SetStyle(STYLE_TEXT_FONT, 30); showWeekLabel->SetStyle(STYLE_LINE_HEIGHT, 35); - showWeekLabel->SetText(weekStr.c_str()); showWeekLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); showWeekLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - showWeekLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - /* -------------------------------- 将组件添加到视图 -------------------------------- */ + showWeekLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 28); + /* ----------------------------------- 电池 ----------------------------------- */ if (batteryimage == nullptr) { batteryimage = new UIImageView(); @@ -411,10 +398,6 @@ namespace OHOS 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(); @@ -424,29 +407,22 @@ namespace OHOS progress->SetViewId("progress1"); // Set style progress->SetValidHeight(19); progress->SetValidWidth(31); - progress->SetValue(value); - // Set BackgroundStyle + + // progress->SetValue(value); + const char *progressImageSrc = "/user/res/Battery/Battery_Normal.bin"; + progress->SetImage(progressImageSrc, nullptr); 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); - Add(showPhoneConnectedStatus); - Add(showEarPhoneConnectedStatus); - Add(showBluetoothConnectedStatus); + + return true; } bool PullUpDownView::InitView() @@ -455,9 +431,17 @@ namespace OHOS InitViewImg(); InitTimeDateWeekLabelAndConnectedStatusImage(); + if (InitBaseData()) + { + RefreshData(); + } + else + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::InitBaseData Error!"); + return false; + } SetTouchable(true); SetIntercept(true); - return true; } @@ -500,7 +484,7 @@ namespace OHOS } else { - ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, dropIconBackground[DNOTDISTURB_INDEX], DROPDOWN_ICONELLIPSEBLACK); + ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, dropIconBackground[DNOTDISTURB_INDEX], DROPDOWN_ICONELLIPSEBLACK); } dropIconBackground[DNOTDISTURB_INDEX]->Invalidate(); } @@ -510,5 +494,91 @@ namespace OHOS return; } } + /*** + * @brief 刷新界面数据 + */ + void PullUpDownView::RefreshData() + { + PRINT("RefreshData Begin!\n"); + // 获取当前时间 + char *dateStr = (char *)malloc(9); + if (uapi_get_YYMMDD_Time(dateStr, '/') != ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get start date"); + free(dateStr); + return; + } + // 解析日期信息 + char *timeStr = (char *)malloc(9); + if (uapi_get_HHMMSS_Time(timeStr, ':', false) != ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get start time"); + free(dateStr); + free(timeStr); + return; + } + // 解析星期信息 + char *weekStr = (char *)malloc(10); + if (uapi_get_WeekStr(weekStr) != ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get week information"); + free(dateStr); + free(timeStr); + free(weekStr); + return; + } + // 获取电池电量信息 + float voltage = 0.0F; + uint8_t value = 0; + value = battery_get_voltage(&voltage); + PRINT("Read ALLData!\n"); + // 更新界面显示 + showTimeLabel->SetText(timeStr); + showWeekLabel->SetText(weekStr); + showDateLabel->SetText(dateStr); + PRINT("Update Label Data!\n"); + + // 更新电池信息 + const char *progressImages[3] = { + "/user/res/Battery/Battery_Limit.bin", // 低电量图片路径 + "/user/res/Battery/Battery_Save.bin", // 中等电量图片路径 + "/user/res/Battery/Battery_Normal.bin" // 正常电量图片路径 + }; + const char *progressImageSrc = nullptr; + for (int i = 0; i < 3; i++) + { + if (value <= (i + 1) * 10) + { + progressImageSrc = progressImages[i]; + PRINT("Update progressImageSrc!\n"); + break; + } + } + progress->SetImage(progressImageSrc, nullptr); + progress->SetValue(value); + PRINT("RefreshData End!\n"); + + // 释放动态分配的内存 + free(dateStr); + free(timeStr); + free(weekStr); + } + + UILabel *PullUpDownView::GetTimeLabel() + { + return showTimeLabel; + } + UILabel *PullUpDownView::GetDateLabel() + { + return showDateLabel; + } + UILabel *PullUpDownView::GetWeekLabel() + { + return showWeekLabel; + } + UIBoxProgress *PullUpDownView::GetProgress() + { + return progress; + } } diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelPower.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelPower.cpp index c77f826c2..c2aa59f82 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelPower.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelPower.cpp @@ -28,13 +28,11 @@ namespace OHOS bool DialModelPower::GetDialFloatData(DialDataType &type, float &out) { (void)type; -#if 1 if (power_ == 101) { UpdatePower(); return true; } -#endif // 获取电池电压值 float voltage = 0.0F; power_ = battery_get_voltage(&voltage); // 进度条0.1~1;电量1~100 @@ -48,12 +46,10 @@ namespace OHOS float voltage = 0.0F; power_ = battery_get_voltage(&voltage); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UpdatePower %d", power_); -#if 1 if (onChangeListener_ != nullptr) { onChangeListener_->OnDialFloatDataUpdate(DialDataType::DATA_TYPE_POWER, power_); } -#endif } } diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index e625e4b56..1a99e13c8 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -475,6 +475,20 @@ errcode_t uapi_get_HHMMSS_Time(char *p_time, char separator, bool include_second return ERRCODE_SUCC; } +const char *weekDays[] = {"星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"}; +errcode_t uapi_get_WeekStr(char *p_week) +{ + time_t currtime; + struct tm *timeinfo; + time(&currtime); + timeinfo = localtime(&currtime); + + // 获取星期信息 + strcpy(p_week, weekDays[timeinfo->tm_wday]); + + return ERRCODE_SUCC; // 假设成功获取星期信息 +} + /// @brief 控制屏幕是否常亮 /// @param turnOnFlag 1:常亮屏幕 /// @param turnOnFlag 0:取消常亮 diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.h b/code/sdk/drivers/peripheral/utils/custom_utils.h index 3cf6b2d33..7413db4cb 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -44,6 +44,8 @@ errcode_t uapi_get_yyyymmddhhmmss_Date(char *date); errcode_t uapi_get_YYMMDD_Time(char *p_time, char separator); /*获取时间*/ errcode_t uapi_get_HHMMSS_Time(char *p_time, char separator, bool include_seconds); +/*获取星期*/ +errcode_t uapi_get_WeekStr(char *p_week); char *uapi_get_local_yyyymmdd_date(void);