From: Caisking <3449750381@qq.com> Date: Wed, 17 Jan 2024 10:38:00 +0000 (+0800) Subject: 更新主界面下滑卡片 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=e7ace76f9375f2a51675b129a100fd821de3638b;p=mirrors%2FFD230.git 更新主界面下滑卡片 --- diff --git a/code/sdk/application/wearable/nativeapp/CMakeLists.txt b/code/sdk/application/wearable/nativeapp/CMakeLists.txt index 4926a50c5..ec62c12dc 100755 --- a/code/sdk/application/wearable/nativeapp/CMakeLists.txt +++ b/code/sdk/application/wearable/nativeapp/CMakeLists.txt @@ -44,6 +44,7 @@ set(PRIVATE_HEADER ${UI_SAMPLE_ROOT}/components ${CMAKE_CURRENT_SOURCE_DIR}/../service/smart_voice/smart_voice_service/interfaces/innerkits/native_c/include ${CMAKE_CURRENT_SOURCE_DIR}/../service/smart_voice/voice_engine_hal/interfaces/innerkits/native_c/include + ${CMAKE_CURRENT_SOURCE_DIR}/../service/timeservice/include ${CMAKE_CURRENT_SOURCE_DIR}/../ohos_deps ${CMAKE_CURRENT_SOURCE_DIR}/../../battery ${CMAKE_CURRENT_SOURCE_DIR}/../../../drivers/drivers/driver/rtc_unified diff --git a/code/sdk/application/wearable/nativeapp/nativeui/dial/include/Digital_clockView.h b/code/sdk/application/wearable/nativeapp/nativeui/dial/include/Digital_clockView.h index 30c447c9e..f0e2fbf68 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/dial/include/Digital_clockView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/dial/include/Digital_clockView.h @@ -1,12 +1,12 @@ -/*** +/*** * @Author: Caisking 3449750381@qq.com * @Date: 2024-01-16 16:17:50 * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-01-17 15:17:01 + * @LastEditTime: 2024-01-17 16:50:57 * @FilePath: /1.FD230/FD230/code/sdk/application/wearable/nativeapp/nativeui/dial/include/Digital_clockView.h - * @Description: + * @Description: * @ - * @Copyright (c) 2024 by Caisking , All Rights Reserved. + * @Copyright (c) 2024 by Caisking , All Rights Reserved. */ #ifndef _Digital_clock_VIEW_H #define _Digital_clock_VIEW_H @@ -36,6 +36,8 @@ #include "battery_hal.h" #include "cJSON.h" #include "sys/time.h" + + extern uint8_t battery_get_voltage(float *voltage); namespace OHOS @@ -73,6 +75,7 @@ namespace OHOS static constexpr int16_t INTERVAL = 30; UISweepClock *sweepClock{nullptr}; }; + /* -------------------------------------------------------------------------- */ class timeLableCallback : public AnimatorCallback { private: @@ -82,10 +85,10 @@ namespace OHOS public: explicit timeLableCallback(UILabel *timeLable, std::string stringtime) : timeLable(timeLable), stringtime(stringtime) {} ~timeLableCallback() {} - // 时钟更新的回调函数 virtual void Callback(UIView *view) override { + /* --------------------------------- 模拟更新时间 --------------------------------- */ // 从字符串中解析小时和分钟 int hour = std::stoi(stringtime.substr(0, 2)); int minute = std::stoi(stringtime.substr(3, 2)); @@ -99,8 +102,9 @@ namespace OHOS // 将小时和分钟转换为字符串,并更新 stringtime stringtime = (hour < 10 ? "0" : "") + std::to_string(hour) + ":" + (minute < 10 ? "0" : "") + std::to_string(minute); timeLable->SetText(stringtime.c_str()); - } + } }; + /* -------------------------------------------------------------------------- */ class myProgressCallback : public AnimatorCallback { private: @@ -219,7 +223,7 @@ namespace OHOS Digital_clockView(); virtual ~Digital_clockView(); static Digital_clockView *GetInstance(void); - + bool InitView(); void DeInit(); void setJsonFilePath(const std::string &filePath); @@ -239,7 +243,7 @@ namespace OHOS void UnLoad(void) override; private: - + UIView::OnDragListener *draglistener{nullptr}; Digital_clockView(Digital_clockView &&) = delete; Digital_clockView &operator=(Digital_clockView &&) = delete; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/dial/src/Digital_clockView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/dial/src/Digital_clockView.cpp index ac24dd2a2..e80240dee 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/dial/src/Digital_clockView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/dial/src/Digital_clockView.cpp @@ -1,3 +1,13 @@ +/*** + * @Author: Caisking 3449750381@qq.com + * @Date: 2024-01-16 19:07:38 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-01-17 18:25:27 + * @FilePath: /1.FD230/FD230/code/sdk/application/wearable/nativeapp/nativeui/dial/src/Digital_clockView.cpp + * @Description: + * @ + * @Copyright (c) 2024 by Caisking , All Rights Reserved. + */ /*** * @Author: Caisking 3449750381@qq.com * @Date: 2024-01-02 11:23:34 @@ -102,6 +112,7 @@ namespace OHOS } return false; } + /* -------------------------------------------------------------------------- */ static Digital_clockView *g_pDigital_clockView{nullptr}; Digital_clockView::Digital_clockView() { @@ -117,6 +128,7 @@ namespace OHOS { return g_pDigital_clockView; } + /* -------------------------------------------------------------------------- */ /** * @description: 生成动画的资源路径数组 * @param {char} *basePath diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/PullUpDownView.h b/code/sdk/application/wearable/nativeapp/nativeui/main/include/PullUpDownView.h index c63342270..e21317967 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/PullUpDownView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/include/PullUpDownView.h @@ -15,35 +15,85 @@ #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 diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/PullUpDownView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/PullUpDownView.cpp index 810d47329..64cf009a1 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/PullUpDownView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/PullUpDownView.cpp @@ -107,6 +107,21 @@ namespace OHOS 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; } @@ -199,7 +214,7 @@ namespace OHOS dropSavePower->SetResizeMode(UIImageView::CENTER); ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, dropSavePower, DROPDOWN_SAVEPOWER); dropSavePower->SetViewId(DROPDOWN_CLICK_SAVEELE); // 进入省电界面 - + dropSavePower->SetTouchable(true); dropSavePower->SetOnClickListener(clickListener); /* ----------------------------------- 找手机 ---------------------------------- */ @@ -223,7 +238,7 @@ namespace OHOS Add(dropSavePower); Add(drofindPhone); } - + /// @brief 初始化时间,日期,星期标签和连接状态 /// @param void void PullUpDownView::InitTimeDateWeekLabelAndConnectedStatusImage(void) @@ -283,7 +298,7 @@ namespace OHOS ScreenModels::GetInstance()->LoadAppImages(DROPDOWN_IAMGES, showBluetoothConnectedStatus, DROPDOWN_BLUETOOTHDISCONNECTED); } /* --------------------------------- 电量状态显示 --------------------------------- */ - + /* ---------------------------------- 时间显示 ---------------------------------- */ showTimeLabel = new UILabel(); if (showTimeLabel == nullptr) @@ -327,7 +342,47 @@ namespace OHOS 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); diff --git a/code/sdk/application/wearable/service/CMakeLists.txt b/code/sdk/application/wearable/service/CMakeLists.txt index a8260d71e..dab7be79e 100755 --- a/code/sdk/application/wearable/service/CMakeLists.txt +++ b/code/sdk/application/wearable/service/CMakeLists.txt @@ -8,3 +8,4 @@ if("CONFIG_SEA_PHS_SUPPORT" IN_LIST DEFINES) add_subdirectory_if_exist(smart_voice) endif() add_subdirectory_if_exist(power_manager) +add_subdirectory_if_exist(timeservice) diff --git a/code/sdk/application/wearable/service/timeservice/CMakeLists.txt b/code/sdk/application/wearable/service/timeservice/CMakeLists.txt new file mode 100644 index 000000000..88742cdbe --- /dev/null +++ b/code/sdk/application/wearable/service/timeservice/CMakeLists.txt @@ -0,0 +1,48 @@ +set(COMPONENT_NAME "timeservice") + +set(PUBLIC_HEADER +) + +set(PRIVATE_HEADER +${CMAKE_CURRENT_SOURCE_DIR}/include +) + +set(SOURCES +${CMAKE_CURRENT_SOURCE_DIR}/src/TimeServiceImpl.c +) + +set(COMPONENT_PUBLIC_CCFLAGS +) + +set(COMPONENT_CCFLAGS + -Wno-error + -Wno-unused-parameter + -fno-exceptions + -fno-unwind-tables + -fno-asynchronous-unwind-tables + -Wno-undef + -Wno-bitwise-op-parentheses + -Wno-shift-op-parentheses + -nostdlibinc + -nostdinc + -nostdlib + -Wno-error=unused-function +) + +set(WHOLE_LINK + true +) + +set(MAIN_COMPONENT + false +) + +set(PUBLIC_DEFINES +) + +set(PRIVATE_DEFINES +) + +build_component() + + diff --git a/code/sdk/application/wearable/service/timeservice/include/TimeService.h b/code/sdk/application/wearable/service/timeservice/include/TimeService.h new file mode 100644 index 000000000..f9cfe19b4 --- /dev/null +++ b/code/sdk/application/wearable/service/timeservice/include/TimeService.h @@ -0,0 +1,33 @@ + +/*** + * @Author: Caisking 3449750381@qq.com + * @Date: 2024-01-17 16:12:26 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-01-17 16:12:28 + * @FilePath: /FD230/code/sdk/application/wearable/service/timeservice/include/TimeService.h + * @Description: + * @ + * @Copyright (c) 2024 by Caisking , All Rights Reserved. + */ +#ifndef TIMESERVICE_H +#define TIMESERVICE_H + +#include +#include + +class TimeUpdateListener +{ +public: + virtual void onTimeUpdate(const std::string &updatedTime) = 0; + virtual ~TimeUpdateListener() {} +}; + +class TimeService +{ +public: + virtual std::string getCurrentTime() = 0; + virtual void subscribeTimeUpdate(TimeUpdateListener *listener) = 0; + virtual ~TimeService() {} +}; + +#endif // TIMESERVICE_H \ No newline at end of file diff --git a/code/sdk/application/wearable/service/timeservice/include/TimeServiceImpl.h b/code/sdk/application/wearable/service/timeservice/include/TimeServiceImpl.h new file mode 100644 index 000000000..da4bbeb45 --- /dev/null +++ b/code/sdk/application/wearable/service/timeservice/include/TimeServiceImpl.h @@ -0,0 +1,29 @@ +/*** + * @Author: Caisking 3449750381@qq.com + * @Date: 2024-01-17 16:12:44 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-01-17 16:23:51 + * @FilePath: /FD230/code/sdk/application/wearable/service/timeservice/include/TimeServiceImpl.h + * @Description: + * @ + * @Copyright (c) 2024 by Caisking , All Rights Reserved. + */ +// TimeServiceImpl.h +#ifndef TIMESERVICEIMPL_H +#define TIMESERVICEIMPL_H + +#include "TimeService.h" +#include +#include + +class TimeServiceImpl : public TimeService { +private: + std::vector listeners; + +public: + std::string getCurrentTime() override; + void subscribeTimeUpdate(TimeUpdateListener* listener) override; + void updateAndNotify(); +}; + +#endif // TIMESERVICEIMPL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/service/timeservice/src/TimeServiceImpl.cpp b/code/sdk/application/wearable/service/timeservice/src/TimeServiceImpl.cpp new file mode 100644 index 000000000..98f55f07e --- /dev/null +++ b/code/sdk/application/wearable/service/timeservice/src/TimeServiceImpl.cpp @@ -0,0 +1,40 @@ +/*** + * @Author: Caisking 3449750381@qq.com + * @Date: 2024-01-17 16:13:11 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-01-17 16:13:13 + * @FilePath: /FD230/code/sdk/application/wearable/service/timeservice/src/TimeServiceImpl.cpp + * @Description: + * @ + * @Copyright (c) 2024 by Caisking , All Rights Reserved. + */ +// TimeServiceImpl.cpp +#include "TimeServiceImpl.h" +#include + +std::string TimeServiceImpl::getCurrentTime() +{ + time_t now = time(0); + tm *localTime = localtime(&now); + char buffer[80]; + strftime(buffer, 80, "%Y-%m-%d %H:%M:%S", localTime); + return std::string(buffer); +} + +void TimeServiceImpl::subscribeTimeUpdate(TimeUpdateListener *listener) +{ + listeners.push_back(listener); +} + +void TimeServiceImpl::updateAndNotify() +{ + while (true) + { + std::string updatedTime = getCurrentTime(); + for (TimeUpdateListener *listener : listeners) + { + listener->onTimeUpdate(updatedTime); + } + std::this_thread::sleep_for(std::chrono::seconds(1)); + } +} \ No newline at end of file