From: Caisking <3449750381@qq.com> Date: Fri, 19 Jan 2024 10:32:17 +0000 (+0800) Subject: 获取系统时间,优化缩约图 X-Git-Tag: release_V1.2.70_20241020_135402~1351^2~9 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=8203707bfc1adf3d6ea19a0cc2ed76e8699d0457;p=mirrors%2FFD230.git 获取系统时间,优化缩约图 --- diff --git a/.vscode/settings.json b/.vscode/settings.json index 07bbe7e76..ae2084d7b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,6 +4,92 @@ "iterator": "cpp", "bitset": "cpp", "string_view": "cpp", - "chrono": "cpp" + "chrono": "cpp", + "algorithm": "cpp", + "__bit_reference": "cpp", + "__bits": "cpp", + "__config": "cpp", + "__debug": "cpp", + "__errc": "cpp", + "__functional_base": "cpp", + "__hash_table": "cpp", + "__locale": "cpp", + "__mutex_base": "cpp", + "__node_handle": "cpp", + "__nullptr": "cpp", + "__split_buffer": "cpp", + "__string": "cpp", + "__threading_support": "cpp", + "__tree": "cpp", + "__tuple": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "cctype": "cpp", + "cinttypes": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "codecvt": "cpp", + "complex": "cpp", + "condition_variable": "cpp", + "csignal": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "exception": "cpp", + "forward_list": "cpp", + "fstream": "cpp", + "functional": "cpp", + "future": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "list": "cpp", + "locale": "cpp", + "map": "cpp", + "memory": "cpp", + "mutex": "cpp", + "new": "cpp", + "numeric": "cpp", + "optional": "cpp", + "ostream": "cpp", + "queue": "cpp", + "random": "cpp", + "ratio": "cpp", + "regex": "cpp", + "set": "cpp", + "sstream": "cpp", + "stack": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "string": "cpp", + "strstream": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "typeinfo": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "utility": "cpp", + "vector": "cpp", + "*.tcc": "cpp", + "memory_resource": "cpp", + "shared_mutex": "cpp", + "thread": "cpp", + "cfenv": "cpp", + "filesystem": "cpp", + "lv_hal_tick.h": "c", + "*.def": "cpp", + "*.inc": "cpp" } } \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/CMakeLists.txt b/code/sdk/application/wearable/nativeapp/CMakeLists.txt index 9207ae679..76d3bbb2e 100755 --- a/code/sdk/application/wearable/nativeapp/CMakeLists.txt +++ b/code/sdk/application/wearable/nativeapp/CMakeLists.txt @@ -54,6 +54,7 @@ set(PRIVATE_HEADER ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/src/ui/frameworks ${ROOT_DIR}/middleware/services/gui/uikit/proprietary/include/service ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/innerkits + ${ROOT_DIR}/middleware/services/gui/lvgl/src/hal ${ROOT_DIR}/open_source/openharmony/foundation/graphic/ui/interfaces/kits/events ${ROOT_DIR}/open_source/openharmony/foundation/graphic/ui/interfaces/kits diff --git a/code/sdk/application/wearable/nativeapp/nativeui/blood/src/BloodView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/blood/src/BloodView.cpp index 131540ea4..74a23607b 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/blood/src/BloodView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/blood/src/BloodView.cpp @@ -208,7 +208,7 @@ namespace OHOS */ void BloodView::DeInit() { - + RemoveAll(); if (background != nullptr) { delete background; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/dial/include/DialPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/dial/include/DialPresenter.h index 09b2bc01c..69d34ea4e 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/dial/include/DialPresenter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/dial/include/DialPresenter.h @@ -1,3 +1,13 @@ +/*** + * @Author: Caisking 3449750381@qq.com + * @Date: 2024-01-17 19:23:30 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-01-19 16:02:49 + * @FilePath: /FD230/code/sdk/application/wearable/nativeapp/nativeui/dial/include/DialPresenter.h + * @Description: + * @ + * @Copyright (c) 2024 by Caisking , All Rights Reserved. + */ #ifndef _Dial_PRESENTER_H #define _Dial_PRESENTER_H @@ -23,9 +33,11 @@ namespace OHOS void OnStop() override; static DialPresenter *GetInstance(); + int WatchFacenum = 0; private: Digital_clockView *g_pDigital_clockView{nullptr}; + DialView *g_pDialView{nullptr}; // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; bool OnClick(UIView &view, const ClickEvent &event) override; bool OnDrag(UIView &view, const DragEvent &event) override; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/dial/include/DialView.h b/code/sdk/application/wearable/nativeapp/nativeui/dial/include/DialView.h index 8dd700d89..8d759cdf7 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/dial/include/DialView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/dial/include/DialView.h @@ -1,13 +1,14 @@ -/*** +/*** * @Author: Caisking 3449750381@qq.com - * @Date: 2024-01-11 18:56:47 + * @Date: 2024-01-17 19:23:30 * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-01-12 15:12:59 - * @FilePath: /1.FD230/FD230/code/sdk/application/wearable/nativeapp/nativeui/dial/include/DialView.h - * @Description: + * @LastEditTime: 2024-01-19 17:10:03 + * @FilePath: /FD230/code/sdk/application/wearable/nativeapp/nativeui/dial/include/DialView.h + * @Description: * @ - * @Copyright (c) 2024 by Caisking , All Rights Reserved. + * @Copyright (c) 2024 by Caisking , All Rights Reserved. */ + #ifndef _Dial_VIEW_H #define _Dial_VIEW_H @@ -38,24 +39,36 @@ namespace OHOS void OnSetUpView() override; void OnTearDownView() override; void OnStop() override; - void Init(); + /* -------------------------------------------------------------------------- */ + void SetLabel(); + void SetImage(); + int GetWatch(); + void SetWatch(int setnum); + bool AddButton(); + bool InitView(); void DeInit(); - - UIView *GetView(); - + bool PreLoad(); + /* -------------------------------------------------------------------------- */ private: UIView::OnDragListener *draglistener{nullptr}; DialView(DialView &&) = delete; DialView &operator=(DialView &&) = delete; UIViewGroup *container_ = nullptr; + UILabel *diallabel = nullptr; + UIImageView *dialimage = nullptr; + UIButton *choose_button = nullptr; + UIButton *left_button = nullptr; + UIButton *right_button = nullptr; + /* -------------------------------------------------------------------------- */ UIScrollView *scrollView1_ = nullptr; - UIButton *button5_ = nullptr; UIButton *button4_ = nullptr; UIButton *button3_ = nullptr; UIButton *button2_ = nullptr; UIButton *button1_ = nullptr; + /* -------------------------------------------------------------------------- */ + bool viewiInitStatus{false}; }; } // namespace OHOS #endif // Dial_PRESENTER_H 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 f7c54b02f..08f91c750 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 @@ -41,7 +41,6 @@ extern uint8_t battery_get_voltage(float *voltage); namespace OHOS { - #define CHANGEBUTTON "changebutton" // 切换表盘按键 class SweepClockCallback : public AnimatorCallback { @@ -74,33 +73,43 @@ namespace OHOS static constexpr int16_t INTERVAL = 30; UISweepClock *sweepClock{nullptr}; }; + /* -------------------------------------------------------------------------- */ + /* -------------------------------------------------------------------------- */ class timeLableCallback : public AnimatorCallback { private: UILabel *timeLable{nullptr}; std::string stringtime; + struct timespec Systime; + struct tm pTM; + time_t seconds; public: - explicit timeLableCallback(UILabel *timeLable, std::string stringtime) : timeLable(timeLable), stringtime(stringtime) {} + explicit timeLableCallback(UILabel *timeLable, std::string stringtime) : timeLable(timeLable), stringtime(stringtime) + { + } ~timeLableCallback() {} // 时钟更新的回调函数 virtual void Callback(UIView *view) override { + /* --------------------------------- 时间 --------------------------------- */ + clock_gettime(CLOCK_MONOTONIC, &Systime); + int SystemTime = Systime.tv_sec; + printf("--getSystemTime::%d--\n", SystemTime); /* --------------------------------- 模拟更新时间 --------------------------------- */ - // 从字符串中解析小时和分钟 - int hour = std::stoi(stringtime.substr(0, 2)); - int minute = std::stoi(stringtime.substr(3, 2)); - // 进位处理 - minute++; - if (minute >= 60) - { - minute = 0; - hour = (hour + 1) % 24; // 修复进位时的处理 - } - // 将小时和分钟转换为字符串,并更新 stringtime - stringtime = (hour < 10 ? "0" : "") + std::to_string(hour) + ":" + (minute < 10 ? "0" : "") + std::to_string(minute); + // 获取系统时间 + time(&seconds); + localtime_r(&seconds, &pTM); + + // 解析小时和分钟 + int hour = pTM.tm_hour; + int minute = pTM.tm_min; + + // 将小时和分钟转换为字符串,并更新显示 + std::string stringtime = (hour < 10 ? "0" : "") + std::to_string(hour) + ":" + (minute < 10 ? "0" : "") + std::to_string(minute); timeLable->SetText(stringtime.c_str()); + printf("--SystemTime::%s--\n", stringtime.c_str()); } }; /* -------------------------------------------------------------------------- */ diff --git a/code/sdk/application/wearable/nativeapp/nativeui/dial/src/DialPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/dial/src/DialPresenter.cpp index 5e30d7431..5ffd7f6d6 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/dial/src/DialPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/dial/src/DialPresenter.cpp @@ -11,7 +11,7 @@ namespace OHOS DialPresenter::DialPresenter() { - + g_pDialView = new DialView(); g_pDialPresenter = this; } @@ -56,7 +56,7 @@ namespace OHOS if (event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) { - //printf("draglistene is ok!\n"); + // printf("draglistene is ok!\n"); NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); } UNUSED(view); @@ -65,42 +65,71 @@ namespace OHOS bool DialPresenter::OnClick(UIView &view, const ClickEvent &event) { + // 根据控件id查找是哪个控件触发了点击回调 +#if 0 + /* -------------------------------------------------------------------------- */ + int setnum = 0; + // 右滑按键 + if (strcmp(view.GetViewId(), "button_right") == 0) + { + // 如果是第5个,则滑向第1个 + setnum = WatchFacenum == 4 ? 0 : WatchFacenum + 1; + printf("--%d--\n", setnum); + WatchFacenum = setnum; + g_pDialView->SetImage(); + g_pDialView->SetLabel(); + } + // 左滑按键 + if (strcmp(view.GetViewId(), "button_left") == 0) + { + // 如果是第1个,则滑向第5个 + setnum = WatchFacenum == 0 ? 4 : WatchFacenum - 1; + printf("--%d--\n", setnum); + WatchFacenum = setnum; + g_pDialView->SetImage(); + g_pDialView->SetLabel(); + } +#endif + /* -------------------------------------------------------------------------- */ + /* -------------------------------------------------------------------------- */ +#if 1 if (strcmp(view.GetViewId(), "kumibutton") == 0) { - //printf("join click\n"); + // printf("join click\n"); const std::string jsonPath = "/user/res/clocks/KUMI.json"; g_pDigital_clockView->setJsonFilePath(jsonPath); NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); } if (strcmp(view.GetViewId(), "flowerbudbutton") == 0) { - //printf("join click\n"); + // printf("join click\n"); const std::string jsonPath = "/user/res/clocks/flowerbud.json"; g_pDigital_clockView->setJsonFilePath(jsonPath); NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); } if (strcmp(view.GetViewId(), "maomaobutton") == 0) { - //printf("join click\n"); + // printf("join click\n"); const std::string jsonPath = "/user/res/clocks/maomao.json"; g_pDigital_clockView->setJsonFilePath(jsonPath); NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); } if (strcmp(view.GetViewId(), "momobutton") == 0) { - //printf("join click\n"); + // printf("join click\n"); const std::string jsonPath = "/user/res/clocks/momo.json"; g_pDigital_clockView->setJsonFilePath(jsonPath); NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); } if (strcmp(view.GetViewId(), "maliaobutton") == 0) { - //printf("join click\n"); + // printf("join click\n"); const std::string jsonPath = "/user/res/clocks/maliao.json"; g_pDigital_clockView->setJsonFilePath(jsonPath); NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); } +#endif return true; } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/dial/src/DialView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/dial/src/DialView.cpp index d8f36a0c5..8c047ffd7 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/dial/src/DialView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/dial/src/DialView.cpp @@ -1,4 +1,13 @@ - +/*** + * @Author: Caisking 3449750381@qq.com + * @Date: 2024-01-17 19:23:24 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-01-19 10:36:39 + * @FilePath: /FD230/code/sdk/application/wearable/nativeapp/nativeui/dial/src/DialView.cpp + * @Description: + * @ + * @Copyright (c) 2024 by Caisking , All Rights Reserved. + */ #include "dial/include/DialView.h" @@ -7,13 +16,28 @@ #include "ui_resource_image.h" #include #include "components/ui_button.h" +#include +#include namespace OHOS { +/* -------------------------------------------------------------------------- */ +#define REDUCED_GRAPH_PATH "/user/res/clocks/Reducedgraph/" + struct WatchFace + { + std::string thumbnailPath; + std::string name; + }; + std::vector watchFaces = { + {REDUCED_GRAPH_PATH "KUMI.bin", "经典表盘"}, + {REDUCED_GRAPH_PATH "momo.bin", "猫猫表盘"}, + {REDUCED_GRAPH_PATH "maliao.bin", "马里奥表盘"}, + {REDUCED_GRAPH_PATH "maomao.bin", "Kitty表盘"}, + {REDUCED_GRAPH_PATH "flowerbud.bin", "花蕾表盘"}}; + /* -------------------------------------------------------------------------- */ + extern int WatchFacenum; static DialView *g_pDialView{nullptr}; - DialView::DialView() { - g_pDialView = this; } @@ -25,18 +49,158 @@ namespace OHOS DialView *DialView::GetInstance() { - return g_pDialView; } - void DialView::Init() + + /*** + * @description: + * @return 设置表盘名称 + */ + void DialView::SetLabel() + { + std::string firstName = watchFaces[DialPresenter::GetInstance()->WatchFacenum].name; + printf("--%s--\n", firstName.c_str()); + // diallabel->SetText(firstName.c_str()); + } + + /*** + * @description: + * @return 设置缩约图背景 + */ + void DialView::SetImage() + { + std::string firstThumbnailPath = watchFaces[DialPresenter::GetInstance()->WatchFacenum].thumbnailPath; + printf("--%s--\n", firstThumbnailPath.c_str()); + const char *buttondefaultImgSrc = firstThumbnailPath.c_str(); + const char *buttontriggeredImgSrc = nullptr; + // choose_button->SetImageSrc(buttondefaultImgSrc, buttontriggeredImgSrc); + } +/* -------------------------------------------------------------------------- */ +#if 0 + /*** + * @description: + * @param + * @return 获取映照索引 + */ + int DialView::GetWatch() + { + printf("WatchFacenum:%d\n", WatchFacenum); + return WatchFacenum; + } + /*** + * @description: + * @param {int} setnum + * @return 设置映照索引 + */ + void DialView::SetWatch(int setnum) + { + WatchFacenum = setnum; + printf("--WatchFacenum:%d\n", WatchFacenum); + } +#endif + /* -------------------------------------------------------------------------- */ + /*** + * @description: + * @return 添加按键 + */ + bool DialView::AddButton() + { + // Add Button to App + if (choose_button == nullptr) + { + choose_button = new UIButton(); + } + choose_button->SetPosition(103, 103); // widget's left position and top position + choose_button->Resize(260, 260); // widget's width and height + choose_button->SetViewId("button_choose"); // Set style + choose_button->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + choose_button->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + + // Set additional property + // Set additional property + char *button1defaultImgSrc = REDUCED_GRAPH_PATH "KUMI.bin"; + char *button1triggeredImgSrc = nullptr; + choose_button->SetImageSrc(button1defaultImgSrc, button1triggeredImgSrc); + choose_button->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + + // Add the CallBack about events + UIView::OnClickListener *button1Click = static_cast(DialPresenter::GetInstance()); + choose_button->SetOnClickListener(button1Click); + + // Add to rootView + container_->Add(choose_button); + choose_button->SetVisible(true); + + /* -------------------------------------------------------------------------- */ + // Add Button to App + if (right_button == nullptr) + { + right_button = new UIButton(); + } + right_button->SetPosition(402, 208); // widget's left position and top position + right_button->Resize(23, 50); // widget's width and height + right_button->SetViewId("button_right"); // Set style + right_button->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + right_button->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + + // Set additional property + char *button2defaultImgSrc = REDUCED_GRAPH_PATH "right_boutton.bin"; + char *button2triggeredImgSrc = nullptr; + right_button->SetImageSrc(button2defaultImgSrc, button2triggeredImgSrc); + right_button->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + + // Add the CallBack about events + UIView::OnClickListener *button2Click = static_cast(DialPresenter::GetInstance()); + right_button->SetOnClickListener(button2Click); + + // Add to rootView + container_->Add(right_button); + right_button->SetVisible(true); + + /* -------------------------------------------------------------------------- */ + + // Add Button to App + if (left_button == nullptr) + { + left_button = new UIButton(); + } + left_button->SetPosition(40, 208); // widget's left position and top position + left_button->Resize(23, 50); // widget's width and height + left_button->SetViewId("left_boutton"); // Set style + left_button->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + left_button->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + + // Set additional property + char *button3defaultImgSrc = REDUCED_GRAPH_PATH "left_boutton.bin"; + char *button3triggeredImgSrc = nullptr; + left_button->SetImageSrc(button3defaultImgSrc, button3triggeredImgSrc); + left_button->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + + // Add the CallBack about events + UIView::OnClickListener *button3Click = static_cast(DialPresenter::GetInstance()); + left_button->SetOnClickListener(button3Click); + + // Add to rootView + container_->Add(left_button); + left_button->SetVisible(true); + + return true; + } + /*** + * @description: + * @return 初始化界面 + */ + bool DialView::InitView() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " void DialView::InitView"); if (container_ == nullptr) { container_ = new UIViewGroup(); container_->SetPosition(0, 0, 466, 466); container_->SetStyle(STYLE_BACKGROUND_OPA, 0); } - + /* -------------------------------------------------------------------------- */ +#if 1 // Add ScrollView to App if (scrollView1_ == nullptr) { @@ -171,8 +335,43 @@ namespace OHOS // Add to scrollView1 scrollView1_->Add(button1_); button1_->SetVisible(true); - } +#endif + /* -------------------------------------------------------------------------- */ + /* -------------------------------------------------------------------------- */ +#if 0 + /* -------------------------------------------------------------------------- */ + std::string firstThumbnailPath = watchFaces[0].thumbnailPath; + std::string firstName = watchFaces[0].name; + printf("firstThumbnailPath:%s -- firstName:%s\n", firstThumbnailPath.c_str(), firstName.c_str()); + /* -------------------------------------------------------------------------- */ + // Add Label to App + if (diallabel == nullptr) + { + diallabel = new UILabel(); + } + diallabel->SetPosition(181, 50); // widget's left position and top positio + diallabel->Resize(200, 60); // widget's width and height + diallabel->SetViewId("titillabel"); // Set style + diallabel->SetStyle(STYLE_TEXT_FONT, 26); + // Set additional property + diallabel->SetText(firstName.c_str()); + diallabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + diallabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + diallabel->SetRollSpeed(0); + diallabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 26); + // Add to rootView + container_->Add(diallabel); + diallabel->SetVisible(true); + /* -------------------------------------------------------------------------- */ + AddButton(); +#endif + return true; + } + /*** + * @description: + * @return {*} + */ void DialView::DeInit() { if (container_ != nullptr) @@ -181,6 +380,32 @@ namespace OHOS delete container_; container_ = nullptr; } + if (diallabel != nullptr) + { + delete diallabel; + diallabel = nullptr; + } + if (dialimage != nullptr) + { + delete dialimage; + dialimage = nullptr; + } + if (choose_button != nullptr) + { + delete choose_button; + choose_button = nullptr; + } + if (left_button != nullptr) + { + delete left_button; + left_button = nullptr; + } + if (right_button != nullptr) + { + delete right_button; + right_button = nullptr; + } + /* -------------------------------------------------------------------------- */ if (scrollView1_ != nullptr) { delete scrollView1_; @@ -211,16 +436,30 @@ namespace OHOS delete button1_; button1_ = nullptr; } + /* -------------------------------------------------------------------------- */ } - UIView *DialView::GetView() + /*** + * @description: + * @return 加载 + */ + bool DialView::PreLoad() { - Init(); - return container_; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " void DialView::PreLoad(void)"); + if (!viewiInitStatus) + { + InitView(); + viewiInitStatus = true; + return true; + } + return false; } void DialView::OnStart() { + View::OnStart(); + BaseView::RootView(Color::Black().full); + container_ = new UIScrollView(); if (container_ == nullptr) { @@ -241,7 +480,11 @@ namespace OHOS container_->SetTouchable(true); container_->SetDraggable(true); - GetView(); + if (!PreLoad()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " void DialView::PreLoad(void) is error"); + } + RootView::GetInstance()->Add(container_); } 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 dd110ea84..dfd3db912 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 @@ -36,11 +36,6 @@ #define PRINT_DEBUG_INFO printf("Function: %s, Line: %d\n", __PRETTY_FUNCTION__, __LINE__); -extern "C" -{ - int rtc_tm_to_time(struct rtc_time *tm, unsigned long *time); -} - namespace OHOS { cJSON *cjson_json = NULL; @@ -64,8 +59,8 @@ namespace OHOS } if (sourceFile.eof()) { - //printf("File overwrite success\n"); // 使用printf打印成功消息 - return; // 返回true表示文件拷贝成功 + // printf("File overwrite success\n"); // 使用printf打印成功消息 + return; // 返回true表示文件拷贝成功 } else { @@ -306,23 +301,16 @@ namespace OHOS } /* -------------------------------------------------------------------------- */ - struct tm local_time; + struct tm pTM; time_t seconds; - seconds = time(NULL); - if (localtime_r(&seconds, &local_time) == NULL) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Digital_clockView::Digital_clockView get localtime error!"); - return false; - } - std::ostringstream ostrHour, ostMin; - ostrHour << local_time.tm_hour; - ostMin << local_time.tm_min; - std::string weekStr = ostrHour.str() + ":" + ostMin.str(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "time = %s!", weekStr.c_str()); - //("weekStr:%s\n", weekStr.c_str()); + time(&seconds); + localtime_r(&seconds, &pTM); + // 解析小时和分钟 + int hour = pTM.tm_hour; + int minute = pTM.tm_min; + // 将小时和分钟转换为字符串,并更新显示 + stringtime = (hour < 10 ? "0" : "") + std::to_string(hour) + ":" + (minute < 10 ? "0" : "") + std::to_string(minute); /* -------------------------------------------------------------------------- */ - stringtime = "20:10"; - // updateClockTime(stringtime); cJSON *digits = cJSON_GetObjectItem(cjson_json, "digits"); std::string playformat = cJSON_GetObjectItem(digits, "playformat")->valuestring; @@ -340,7 +328,7 @@ namespace OHOS addImageView(hour1_left, hour1_top, (digitspath + "point.bin").c_str(), "colon", digitsize * 2 + 10, 20); addImageView(hour1_left, hour1_top, (digitspath + stringtime.substr(3, 1) + ".bin").c_str(), "minute1", digitsize * 3, 0); addImageView(hour1_left, hour1_top, (digitspath + stringtime.substr(4, 1) + ".bin").c_str(), "minute2", digitsize * 4, 0); - //printf("--%s--\n", digitspath.c_str()); + // printf("--%s--\n", digitspath.c_str()); if (mytimeimageCallback_ == nullptr) { mytimeimageCallback_ = new mytimeimageCallback(hour1, hour2, minute1, minute2, digitspath, stringtime); @@ -656,7 +644,7 @@ namespace OHOS */ bool Digital_clockView ::AddButton() { - + // Add Button to App if (changebutton == nullptr) { @@ -667,11 +655,11 @@ namespace OHOS changebutton->SetViewId(CHANGEBUTTON); // Set style changebutton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); changebutton->SetStyle(STYLE_BACKGROUND_OPA, 0x00); - + // Set additional property changebutton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED); changebutton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); - + // Add the CallBack about events UIView::OnLongPressListener *buttonLongPress = static_cast(MainPresenterSample::GetInstance()); changebutton->SetOnLongPressListener(buttonLongPress); @@ -689,6 +677,9 @@ namespace OHOS if (loadJsonData(JosnfilePath)) { std::string Dialtype = cJSON_GetObjectItem(cjson_json, "Dialtype")->valuestring; + /* -------------------------------------------------------------------------- */ + + /* -------------------------------------------------------------------------- */ Initbackground(); if (Dialtype == "pointer") { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingView.cpp index 5e8c734ef..0db223d38 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingView.cpp @@ -119,7 +119,7 @@ namespace OHOS const char *button4defaultImgSrc = PNG_TRAING_BOUTTONMORE_IMAGE; char *button4triggeredImgSrc = nullptr; ButtonMore->SetImageSrc(button4defaultImgSrc, button4triggeredImgSrc); - //ButtonMore->SetText(traingmore.c_str()); + // ButtonMore->SetText(traingmore.c_str()); ButtonMore->SetLabelPosition(0, 70); ButtonMore->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20); ButtonMore->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff19ff41, UIButton::PRESSED); @@ -204,7 +204,7 @@ namespace OHOS // Add to rootView Add(image3); - + return true; } @@ -229,6 +229,7 @@ namespace OHOS void TraingView::DeInit() { + RemoveAll(); if (titleLabel != nullptr) { delete titleLabel; diff --git a/code/sdk/application/wearable/service/power_manager/src/power_display_service.c b/code/sdk/application/wearable/service/power_manager/src/power_display_service.c index 5f86518b1..0472fdfa5 100755 --- a/code/sdk/application/wearable/service/power_manager/src/power_display_service.c +++ b/code/sdk/application/wearable/service/power_manager/src/power_display_service.c @@ -20,7 +20,7 @@ #include "touch_screen_def.h" #include "display_state_machine.h" -#define DISPLAY_AUTO_POWER_OFF_PERIOD_MS (1000 * 10) //10秒 +#define DISPLAY_AUTO_POWER_OFF_PERIOD_MS (1000 * 120) //120秒 #define DISPLAY_DEFAULT_BRIGHTNESS 50 #define POWER_DISPLAY_QUEUE_MAX_SIZE 64 #define POWER_DISPLAY_MAX_SIZE 0x10