From b64b4add8f574b8eaaab17b7a15dc0e1b4e16623 Mon Sep 17 00:00:00 2001 From: aliyun3243248791 Date: Tue, 22 Apr 2025 03:16:32 +0000 Subject: [PATCH] Merge #1728 into sdk650 from refs/changes/1728/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Code review from aliyun3243248791 * refs/changes/1728/head: (4 commits squashed) - 【省电模式】UI - 【睡眠】UI - 【计算器】UI - Merge branch 'sdk650' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk650 Signed-off-by: 薛文强 Merged-by: Caisking <3449750381@qq.com> CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/1728 --- .../calculator/include/CalculatorModel.h | 44 + .../calculator/include/CalculatorPresenter.h | 42 + .../calculator/include/CalculatorView.h | 79 ++ .../calculator/src/CalculatorModel.cpp | 152 +++ .../calculator/src/CalculatorPresenter.cpp | 177 +++ .../calculator/src/CalculatorView.cpp | 669 +++++++++++ .../saveele/include/SaveBatPresenter.h | 59 + .../nativeui/saveele/include/SaveBatView.h | 137 +++ .../nativeui/saveele/include/SaveEleModel.h | 43 + .../saveele/include/SaveElePresenter.h | 41 + .../nativeui/saveele/include/SaveEleView.h | 50 + .../nativeui/saveele/src/SaveBatPresenter.cpp | 148 +++ .../nativeui/saveele/src/SaveBatView.cpp | 855 ++++++++++++++ .../nativeui/saveele/src/SaveEleModel.cpp | 20 + .../nativeui/saveele/src/SaveElePresenter.cpp | 83 ++ .../nativeui/saveele/src/SaveEleView.cpp | 149 +++ .../nativeui/sleep/include/SleepCardView.h | 37 + .../sleep/include/SleepControlPresenter.h | 55 + .../nativeui/sleep/include/SleepControlView.h | 74 ++ .../nativeui/sleep/include/SleepModel.h | 170 +++ .../nativeui/sleep/include/SleepModelC.h | 31 + .../nativeui/sleep/include/SleepNapView.h | 69 ++ .../nativeui/sleep/include/SleepTimeView.h | 73 ++ .../nativeui/sleep/include/SleepView.h | 60 + .../nativeui/sleep/src/SleepCardView.cpp | 103 ++ .../sleep/src/SleepControlPresenter.cpp | 121 ++ .../nativeui/sleep/src/SleepControlView.cpp | 217 ++++ .../nativeui/sleep/src/SleepModel.cpp | 1019 +++++++++++++++++ .../nativeui/sleep/src/SleepNapView.cpp | 149 +++ .../nativeui/sleep/src/SleepTimeView.cpp | 194 ++++ .../nativeui/sleep/src/SleepView.cpp | 254 ++++ .../config/target_config/brandy/config.py | 1 + .../zhihui/utils/custom_fileoperate_service.c | 12 +- 33 files changed, 5381 insertions(+), 6 deletions(-) create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/calculator/include/CalculatorModel.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/calculator/include/CalculatorPresenter.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/calculator/include/CalculatorView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/calculator/src/CalculatorModel.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/calculator/src/CalculatorPresenter.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/calculator/src/CalculatorView.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/include/SaveBatPresenter.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/include/SaveBatView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/include/SaveEleModel.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/include/SaveElePresenter.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/include/SaveEleView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveBatPresenter.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveBatView.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveEleModel.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveElePresenter.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveEleView.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepCardView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepControlPresenter.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepControlView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepModel.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepModelC.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepNapView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepTimeView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/src/SleepCardView.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/src/SleepControlPresenter.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/src/SleepControlView.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/src/SleepModel.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/src/SleepNapView.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/src/SleepTimeView.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/src/SleepView.cpp diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/calculator/include/CalculatorModel.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/calculator/include/CalculatorModel.h new file mode 100644 index 000000000..9412c3319 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/calculator/include/CalculatorModel.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: CalculatorModel.h + * Author: + * Create: 2021-10-12 + */ +#ifndef CALCULATOR_MODEL_H +#define CALCULATOR_MODEL_H + +#include "los_mux.h" +#include "string" +#include "PhoneService.h" +#include "AppViewIDs.h" +#include "components/ui_label_ext.h" +#include"ui_resource_string.h" +#include "message.h" +#include "msg_center.h" +#include "stack" + +namespace OHOS { + + +class CalculatorModel { +public: + static CalculatorModel *GetInstance(void); + + + void number_push_stack(double ); + void symbol_push_stack(char symbol); + double calculate_stack(); + uint8_t get_stcak_size(); + void symbol_stack_top_uddata(char data); + void clean_stack(); + void symbol_stack_pop(void); +private: + CalculatorModel(); + CalculatorModel(const CalculatorModel &); + virtual ~CalculatorModel(); + std::stack numberStack; + std::stack symbolStack; + +}; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/calculator/include/CalculatorPresenter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/calculator/include/CalculatorPresenter.h new file mode 100644 index 000000000..8550f31dc --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/calculator/include/CalculatorPresenter.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: CalculatorPresenter.h + * Author: + * Create: 2021-10-12 + */ + +#ifndef CALCULATOR_PRESENTER_H +#define CALCULATOR_PRESENTER_H + +#include "Presenter.h" +#include "ohos_types.h" +#include "CallerLogModel.h" +//#include "BaseView.h" +#include "cmsis_os.h" + +namespace OHOS { +class CalculatorView; +class CalculatorPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener, + public RootView::OnKeyActListener +{ +public: + CalculatorPresenter(); + ~CalculatorPresenter() override; + + void OnStart() override; + + + static CalculatorPresenter *GetInstance(void); + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; + bool OnDragEnd(UIView &view, const DragEvent &event) override; + + +private: + +}; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/calculator/include/CalculatorView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/calculator/include/CalculatorView.h new file mode 100644 index 000000000..f892a1001 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/calculator/include/CalculatorView.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: CalculatorView.h + * Author: + * Create: 2021-10-12 + */ + +#ifndef CALCULATOR_VIEW_H +#define CALCULATOR_VIEW_H + +#include "View.h" +#include "CalculatorPresenter.h" +#include "CalculatorView.h" +//#include "BaseView.h" +#include "components/ui_view_group.h" +#include "components/ui_image_animator.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_label_ext.h" +#include "components/ui_label_button.h" +#include "components/ui_list.h" +#include "components/abstract_adapter.h" +#include "components/ui_image_view.h" + +#include "PhoneService.h" +#include "vector.h" +#include "ChangeSliceListener.h" +#include "cmsis_os2.h" + +namespace OHOS { + +class CalculatorView : + public UIViewGroup, +public View { +public: + CalculatorView(); + ~CalculatorView(); + + + void OnStart() override; + static CalculatorView *GetInstance(); + void number_text_updata_buf(const char *buf); + void symbol_text_updata_buf(const char *buf); + void symbol_text_updata_single_buf(const char *buf); + void symbol_text_updata_calculate_buf(const char *buf); + + void start_call_roll_timer(); + void start_call_roll_timer_move(); + + void show_hint_label(bool data); + + void show_long_label(); + bool string_have_dot(std::string buf); + + osTimerId_t call_roll_timer=NULL; + osTimerId_t call_roll_timer_move=NULL; + +private: + uint8_t number_falg=0; + bool button_init(); + bool Label_init(); + UILabelButton *Button[20]={nullptr}; + + UIImageView *image1_{nullptr}; + + UIViewGroup *group{nullptr}; + UILabel *number{nullptr}; + UILabelExt *hint{nullptr}; + + std::string number_string=" "; + + UIView::OnClickListener* clickLeftListener{nullptr}; + UIView:: OnDragListener* dragListener{nullptr}; + + +}; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/calculator/src/CalculatorModel.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/calculator/src/CalculatorModel.cpp new file mode 100644 index 000000000..c2a67bd91 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/calculator/src/CalculatorModel.cpp @@ -0,0 +1,152 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: CalculatorModel.cpp + * Author: + * Create: 2021-10-12 + */ +#include "DialingScreenView.h" + +#include "service_id_define.h" +#include "cmsis_os.h" +#include "samgr_lite.h" +#include "calculator/include/CalculatorModel.h" + +#ifdef __cplusplus +extern "C" { +#endif + +using namespace OHOS; + + +static bool g_isWatchCallView = false; + +CalculatorModel::CalculatorModel() +{ + +} + +CalculatorModel::~CalculatorModel() +{ + +} + + +void CalculatorModel:: number_push_stack(double data) +{ + // printf("%lf\r\n",data); + if(!symbolStack.empty()) + { + if(symbolStack.top()=='-') + { + char symbol_= symbolStack.top(); + symbolStack.pop(); + data=-data; + symbolStack.push('+'); + + } + } + numberStack.push(data); +} + + +void CalculatorModel:: symbol_stack_top_uddata(char data) +{ + // printf("%c\r\n",data); + if(!symbolStack.empty()) + { + symbolStack.pop(); + symbolStack.push(data); + } +} + + +void CalculatorModel:: symbol_stack_pop(void) +{ + if(!symbolStack.empty()) + { + symbolStack.pop(); + } +} + +uint8_t CalculatorModel::get_stcak_size() +{ + return numberStack.size(); +} + +void CalculatorModel:: symbol_push_stack(char symbol) +{ + // printf("%c\r\n",symbol); + + if(numberStack.empty()) + { + return ; + } + symbolStack.push(symbol); + return ; + +} + +void CalculatorModel:: clean_stack() +{ + while (!numberStack.empty()) + { + numberStack.pop(); + } + + while (!symbolStack.empty()) + { + symbolStack.pop(); + } +} + +double CalculatorModel:: calculate_stack() +{ + double sum=0; + if(numberStack.empty()) + return sum; + double number_1= numberStack.top(); + numberStack.pop(); + sum=number_1; + while (!numberStack.empty()) + { + double number_= numberStack.top(); + numberStack.pop(); + + if(symbolStack.empty()) + break; + char symbol= symbolStack.top(); + if(symbol=='+') + { + sum+=number_; + } + if(symbol=='x') + { + sum*=number_; + } + if(symbol=='-') + { + sum=-number_; + } + if(symbol=='/') + { + if(sum==0) + { + return sum; + } + sum=number_/sum; + } + // printf("sum:%lf\r\n",sum); + } + return sum; +} + + +CalculatorModel *CalculatorModel::GetInstance(void) +{ + static CalculatorModel callLogModel; + return &callLogModel; +} + +#ifdef __cplusplus +} +#endif diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/calculator/src/CalculatorPresenter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/calculator/src/CalculatorPresenter.cpp new file mode 100644 index 000000000..e2162996b --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/calculator/src/CalculatorPresenter.cpp @@ -0,0 +1,177 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: CalculatorPresenter.cpp + * Author: + * Create: 2021-10-12 + */ + +#include "calculator/include/CalculatorPresenter.h" +#include "calculator/include/CalculatorView.h" +#include "gfx_utils/mem_check.h" +#include "common/key_code.h" +#include "custom_utils.h" +#include "NativeRegisterManager.h" +#include "uicomponents/UIComponents.h" +namespace OHOS { + + REGIST_MENU_PRO( VIEW_CALCULATOR, CalculatorView, CalculatorPresenter, + PNG_APPLIST_INFORMATION_IMAGE_BIG, PNG_APPLIST_INFORMATION_IMAGE, PNG_APPLIST_INFORMATION_IMAGE, "计算器", STR_CALCULATOR); + +static CalculatorPresenter *g_pMainView = nullptr; +CalculatorPresenter::CalculatorPresenter() +{ + g_pMainView = this; +#ifdef MEM_CHECK + MemCheck::GetInstance()->EnableLeakCheck(true); +#endif +} + +CalculatorPresenter::~CalculatorPresenter() +{ + g_pMainView = nullptr; +#ifdef MEM_CHECK + MemCheck::GetInstance()->EnableLeakCheck(false); +#endif +} + +CalculatorPresenter *CalculatorPresenter::GetInstance(void) +{ + return g_pMainView; +} + +void CalculatorPresenter::OnStart() +{ + Presenter::OnStart(); +} + + + + +bool CalculatorPresenter::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnClick %s",view.GetViewId()); + if (strcmp(view.GetViewId(), "0") == 0) { + CalculatorView::GetInstance()->number_text_updata_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), "1") == 0) + { + CalculatorView::GetInstance()->number_text_updata_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), "2") == 0) + { + CalculatorView::GetInstance()->number_text_updata_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), "3") == 0) + { + CalculatorView::GetInstance()->number_text_updata_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), "4") == 0) + { + CalculatorView::GetInstance()->number_text_updata_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), "5") == 0) + { + CalculatorView::GetInstance()->number_text_updata_buf(view.GetViewId()); + return true; + } + + else if (strcmp(view.GetViewId(), "6") == 0) + { + CalculatorView::GetInstance()->number_text_updata_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), "7") == 0) + { + CalculatorView::GetInstance()->number_text_updata_buf(view.GetViewId()); + return true; + }else if (strcmp(view.GetViewId(), "8") == 0) + { + CalculatorView::GetInstance()->number_text_updata_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), "9") == 0) + { + CalculatorView::GetInstance()->number_text_updata_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), ".") == 0) + { + CalculatorView::GetInstance()->number_text_updata_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), "÷") == 0) + { + CalculatorView::GetInstance()->symbol_text_updata_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), "x") == 0) + { + CalculatorView::GetInstance()->symbol_text_updata_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), "+") == 0) + { + CalculatorView::GetInstance()->symbol_text_updata_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), "-") == 0) + { + CalculatorView::GetInstance()->symbol_text_updata_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), "C") == 0) + { + CalculatorView::GetInstance()->symbol_text_updata_single_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), "%") == 0) + { + CalculatorView::GetInstance()->symbol_text_updata_single_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(), "=") == 0) + { + CalculatorView::GetInstance()->symbol_text_updata_calculate_buf(view.GetViewId()); + return true; + } + else if (strcmp(view.GetViewId(),"D") == 0) + { + CalculatorView::GetInstance()->symbol_text_updata_single_buf(view.GetViewId()); + return true; + } + + return false; +} + +bool CalculatorPresenter::OnDragEnd(OHOS::UIView& view, const OHOS::DragEvent& event) +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainCallingPresenter OnDragEnd"); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) + { + if(event.GetPreLastPoint().x-event.GetStartPoint().x>150) + NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); + } + return true; +} + +bool CalculatorPresenter::OnKeyAct(UIView &view, const KeyEvent &event) +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayPresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + uint16_t keyState = event.GetState(); + // 如果是power键就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); + } + return true; + +} +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/calculator/src/CalculatorView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/calculator/src/CalculatorView.cpp new file mode 100644 index 000000000..d032f7bb2 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/calculator/src/CalculatorView.cpp @@ -0,0 +1,669 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: CalculatorView.cpp + * Author: + * Create: 2021-10-12 + */ + +#include "calculator/include/CalculatorView.h" +#include "calculator/include/CalculatorPresenter.h" +#include "calculator/include/CalculatorModel.h" +#include "wearable_log.h" +#include +#include +#include + +namespace OHOS { + +static CalculatorView *g_pMainView = nullptr; +CalculatorView::CalculatorView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "::CalculatorView::CalculatorView "); + g_pMainView = this; +} + +CalculatorView::~CalculatorView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "::CalculatorView::~CalculatorView "); + RootView::GetInstance()->ClearOnKeyActListener(); + g_pMainView = nullptr; + group->RemoveAll(); + if(number) + { + delete number; + number =nullptr; + } + for(int i=0;i<20;i++) + { + if(Button[i]) + { + delete Button[i]; + Button[i] =nullptr; + } + } + if(image1_) + { + delete image1_; + image1_=nullptr; + } + if(hint) + { + delete hint; + hint=nullptr; + } + if(group) + { + delete group; + group =nullptr; + } + + if(call_roll_timer) + { + osTimerStop(call_roll_timer); + osTimerDelete(call_roll_timer); + call_roll_timer = NULL; + } + + if(call_roll_timer_move) + { + osTimerStop(call_roll_timer_move); + osTimerDelete(call_roll_timer_move); + call_roll_timer_move = NULL; + } + +} +static int8_t roll_falg=0;//0.1s一次变换 + +static int8_t roll_falg_2=0;//0.1s一次变换 + + static void label_Timer_CallBack(int data) +{ + roll_falg--; + if(roll_falg<=0) + { + if(CalculatorView::GetInstance()) + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(&CalculatorView::show_hint_label, CalculatorView::GetInstance(),false)); + } + + + if(g_pMainView->call_roll_timer) + { + osTimerStop(g_pMainView->call_roll_timer); + osTimerDelete(g_pMainView->call_roll_timer); + g_pMainView->call_roll_timer = NULL; + } + } +} + +static void label_Timer_CallBack_move(int data) +{ + roll_falg_2--; + if(roll_falg_2<=0) + { + if(CalculatorView::GetInstance()) + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(&CalculatorView::show_long_label, CalculatorView::GetInstance())); + } + + if(g_pMainView->call_roll_timer_move) + { + osTimerStop(g_pMainView->call_roll_timer_move); + osTimerDelete(g_pMainView->call_roll_timer_move); + g_pMainView->call_roll_timer_move = NULL; + } + } +} + + + +CalculatorView *CalculatorView::GetInstance() +{ + return g_pMainView; +} + + +void CalculatorView::show_hint_label(bool data) +{ + hint->SetVisible(data); + Invalidate(); +} + +void CalculatorView::show_long_label(void) +{ + number->SetText(number_string.c_str()); + number->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + + Invalidate(); +} + +void CalculatorView::start_call_roll_timer() +{ + uint32_t tick; + osStatus_t retTimer; + if(call_roll_timer) + { + roll_falg=10; + } + else + { + roll_falg=10; + + call_roll_timer = osTimerNew((osTimerFunc_t)label_Timer_CallBack, osTimerPeriodic, NULL, NULL); + tick =100;// osMs2Tick(1000); + retTimer = osTimerStart(call_roll_timer, tick); + if (retTimer != osOK && call_roll_timer != NULL) { + osTimerDelete(call_roll_timer); + call_roll_timer = NULL; + return ; + } + } +} + + +void CalculatorView::start_call_roll_timer_move() +{ + uint32_t tick; + osStatus_t retTimer; + if(call_roll_timer_move) + { + roll_falg_2=15; + } + else + { + roll_falg_2=15; + + call_roll_timer_move = osTimerNew((osTimerFunc_t)label_Timer_CallBack_move, osTimerPeriodic, NULL, NULL); + tick =100;// osMs2Tick(1000); + retTimer = osTimerStart(call_roll_timer_move, tick); + if (retTimer != osOK && call_roll_timer_move != NULL) { + osTimerDelete(call_roll_timer_move); + call_roll_timer_move = NULL; + return ; + } + } +} + +bool CalculatorView::string_have_dot(std::string buf) +{ + for(int i=0;i15) + { + //超出长度限制 + start_call_roll_timer(); + show_hint_label(true); + return; + } + + number_string=number_string+buf; + + // if(number_string.length()>12) + // { + // number->SetText(number_string.c_str()+number_string.length()-12); + // number->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + // number_falg=1; + // start_call_roll_timer_move(); + // Invalidate(); + // return; + // } + + number->SetText(number_string.c_str()); + number->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + + number_falg=1; + + Invalidate(); + return; +} + +void CalculatorView::symbol_text_updata_buf(const char *buf) +{ + + if(g_pMainView->call_roll_timer_move) + { + osTimerStop(g_pMainView->call_roll_timer_move); + osTimerDelete(g_pMainView->call_roll_timer_move); + g_pMainView->call_roll_timer_move = NULL; + } + + char new_buf[64]={0}; + + std::string text_buf=number_string; + if(number_falg==0) + { + if(strcmp(buf,"÷")==0) + CalculatorModel::GetInstance()->symbol_stack_top_uddata('/'); + else + CalculatorModel::GetInstance()->symbol_stack_top_uddata(buf[0]); + + number_string=new_buf; + number->SetText(buf); + number->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + + Invalidate(); + return; + } + double number_float=strtod(text_buf.c_str(),NULL); + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%lf %s",number_float,text_buf.c_str()); + + char new_buf_[64]={0}; + sprintf_s(new_buf_,64,"%.010lf",number_float); + number_float=strtod(new_buf_,NULL); + + CalculatorModel::GetInstance()->number_push_stack(number_float); + + if( CalculatorModel::GetInstance()->get_stcak_size()>=2) + { + number_float =CalculatorModel::GetInstance()->calculate_stack(); + CalculatorModel::GetInstance()->number_push_stack(number_float); + Invalidate(); + + } + + sprintf_s(new_buf,64,"%s",buf); + + number_string=new_buf; + number->SetText(new_buf); + number->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + + Invalidate(); + + if(strcmp(buf,"÷")==0) + CalculatorModel::GetInstance()->symbol_push_stack('/'); + else + CalculatorModel::GetInstance()->symbol_push_stack(buf[0]); + + number_falg=0; + + return; +} + +void CalculatorView::symbol_text_updata_single_buf(const char *buf) +{ + if(g_pMainView->call_roll_timer_move) + { + osTimerStop(g_pMainView->call_roll_timer_move); + osTimerDelete(g_pMainView->call_roll_timer_move); + g_pMainView->call_roll_timer_move = NULL; + } + + char new_buf[64]={0}; + + std::string text_buf=number_string; + + double number_float=strtod(text_buf.c_str(),NULL); + if(buf[0]=='C') + { + CalculatorModel::GetInstance()->clean_stack(); + number->SetText(""); + number_string=""; + Invalidate(); + } + else if (buf[0]=='%') + { + number_float=0.01*number_float; + + double number_float_=number_float; + int decimal_places = 0; + double frac; + + while (modf(number_float_ * pow(10, decimal_places), &frac) != 0.0f) + { + decimal_places++; + } + + // printf("该浮点数的小数部分有 %d %lf 位。\n", decimal_places,number_float); + switch (decimal_places) + { + case 0: + sprintf_s(new_buf,64,"%.00lf",number_float); + break; + case 1: + sprintf_s(new_buf,64,"%.01lf",number_float); + break; + case 2: + sprintf_s(new_buf,64,"%.02lf",number_float); + break; + case 3: + sprintf_s(new_buf,64,"%.03lf",number_float); + break; + case 4: + sprintf_s(new_buf,64,"%.04lf",number_float); + break; + case 6: + sprintf_s(new_buf,64,"%.06lf",number_float); + break; + case 7: + sprintf_s(new_buf,64,"%.07lf",number_float); + break; + case 8: + sprintf_s(new_buf,64,"%.08lf",number_float); + break; + default: + sprintf_s(new_buf,64,"%.09lf",number_float); + break; + } + number_string=new_buf; + number->SetText(new_buf); + number->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + Invalidate(); + } + else if (buf[0]=='D') + { + number_string.pop_back(); + number->SetText(number_string.c_str()); + number->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + if(number_falg==0) + { + CalculatorModel::GetInstance()->symbol_stack_pop(); + number_falg=1; + } + else + { + number_falg=1; + } + + + Invalidate(); + } + + return; +} + +void CalculatorView::symbol_text_updata_calculate_buf(const char *buf) +{ + if(g_pMainView->call_roll_timer_move) + { + osTimerStop(g_pMainView->call_roll_timer_move); + osTimerDelete(g_pMainView->call_roll_timer_move); + g_pMainView->call_roll_timer_move = NULL; + } + + char new_buf[64]={0}; + std::string text_buf=number_string; + double number_float=0; + + if(text_buf[0]>='0' && text_buf[0]<='9') + { + number_float=strtod(text_buf.c_str(),NULL); + char new_buf_[64]={0}; + sprintf_s(new_buf_,64,"%.010lf",number_float); + number_float=strtod(new_buf_,NULL); + + CalculatorModel::GetInstance()->number_push_stack(number_float); + } + + number_float =CalculatorModel::GetInstance()->calculate_stack(); + + char new_buf_[64]={0}; + sprintf_s(new_buf_,64,"%.010lf",number_float); + number_float=strtod(new_buf_,NULL); + + double number_float_=number_float; + int decimal_places = 0; + double frac; + + while (modf(number_float_ * pow(10, decimal_places), &frac) != 0.0f) + { + decimal_places++; + } + switch (decimal_places) + { + case 0: + sprintf_s(new_buf,64,"%.00lf",number_float); + break; + case 1: + sprintf_s(new_buf,64,"%.01lf",number_float); + break; + case 2: + sprintf_s(new_buf,64,"%.02lf",number_float); + break; + case 3: + sprintf_s(new_buf,64,"%.03lf",number_float); + break; + case 4: + sprintf_s(new_buf,64,"%.04lf",number_float); + break; + case 6: + sprintf_s(new_buf,64,"%.06lf",number_float); + break; + case 7: + sprintf_s(new_buf,64,"%.07lf",number_float); + break; + case 8: + sprintf_s(new_buf,64,"%.08lf",number_float); + break; + default: + sprintf_s(new_buf,64,"%.09lf",number_float); + break; + } + + // CalculatorModel::GetInstance()->number_push_stack(number_float); + number_falg=2; + + number_string=new_buf; + + number->SetText(new_buf); + number->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + Invalidate(); + + + // number->SetText(""); + return; +} + + + + +static char *dial_id_str[]={"7","8","9","C","%","4","5","6","÷","x","1","2","3","-","+","","0",".","=",""}; + +bool CalculatorView::button_init() +{ + uint8_t showdial_i=0; + for(int i=0;i<4;i++) + { + for(int j=0;j<5;j++) + { + if(showdial_i==15 || showdial_i==19) + { + showdial_i++; + continue; + } + if (Button[showdial_i] == nullptr) { + Button[showdial_i] = new UILabelButton(); + } + if(Button[showdial_i]==nullptr) + { + return false; + } + Button[showdial_i]->SetPosition(17+(j*88), 140+(i*68)); // widget's left position and top position + + Button[showdial_i]->Resize(80, 60); // widget's width and height + Button[showdial_i]->SetViewId(dial_id_str[showdial_i]);// Set style + + Button[showdial_i]->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + Button[showdial_i]->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff191919, UIButton::PRESSED); + if(j>2) + { + Button[showdial_i]->SetStyle(STYLE_BACKGROUND_COLOR, 0xFFFF8A36); + Button[showdial_i]->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xFFFF8A36, UIButton::PRESSED); + if(i==0) + { + Button[showdial_i]->SetStyle(STYLE_BACKGROUND_COLOR, 0xFFAAAAAA); + Button[showdial_i]->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xFFAAAAAA, UIButton::PRESSED); + } + } + + Button[showdial_i]->SetText(dial_id_str[showdial_i]); + Button[showdial_i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 40); + + + group->Add(Button[showdial_i]); + Button[showdial_i]->SetVisible(true); + + clickLeftListener = (UIView::OnClickListener*)OHOS::CalculatorPresenter::GetInstance(); + if (clickLeftListener == nullptr) { + return false; + } + + Button[showdial_i]->SetOnClickListener(clickLeftListener); + + showdial_i++; + } + } + + return true; +} + +bool CalculatorView::Label_init() +{ + if (number == nullptr) { + number = new UILabel(); + } + if(number==nullptr) + { + return false; + } + number->SetPosition(65, 73); // widget's left position and top position + number->Resize(310, 60); // widget's width and height + number->SetViewId("label5");// Set style + number->SetStyle(STYLE_TEXT_FONT, 50); + + // Set additional property + number->SetText(""); + number->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + number->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + number->SetRollSpeed(0); + number->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 50); + + // Add to rootView + group->Add(number); + + number->SetVisible(true); + + if (image1_ == nullptr) { + image1_ = new UIImageView(); + } + image1_->SetPosition(378, 85); // widget's left position and top position + image1_->Resize(60, 60); // widget's width and height + image1_->SetViewId("D");// Set style + image1_->SetAutoEnable(false); + image1_->SetResizeMode(UIImageView::CENTER); + + + char* DimagesPath = "/user/res/Vector.bin"; + + image1_->SetSrc(DimagesPath); + clickLeftListener = (UIView::OnClickListener*)OHOS::CalculatorPresenter::GetInstance(); + if (clickLeftListener == nullptr) { + return false; + } + + image1_->SetOnClickListener(clickLeftListener); + image1_->SetTouchable(true); + // Add to rootView + group->Add(image1_); + + image1_->SetVisible(true); + + + if (hint == nullptr) { + hint = new UILabelExt(); + } + hint->SetPosition(109, 169); // widget's left position and top position + hint->Resize(247, 60); // widget's width and height + hint->SetViewId("label2");// Set style + hint->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + hint->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + hint->SetStyle(STYLE_BORDER_RADIUS, 25); + hint->SetStyle(STYLE_PADDING_BOTTOM, 8); + hint->SetStyle(STYLE_TEXT_FONT, 30); + hint->SetStyle(STYLE_LINE_HEIGHT, 20); + + // Set additional property + hint->SetTextId(STR_NUM_LENGTH); + hint->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + hint->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + hint->SetRollSpeed(0); + hint->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + group->Add(hint); + hint->SetVisible(false); + + + return true; +} + +void CalculatorView::OnStart() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CalculatorView::OnStart"); + View::OnStart(); + + AddViewToRootContainer(new UIViewGroup()); + GetRootContainer()->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + GetRootContainer()->SetTouchable(true); + GetRootContainer()->SetDraggable(true); + + RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::CalculatorPresenter::GetInstance(); + RootView::GetInstance()->SetOnKeyActListener(keyactListener); + + group = new UIViewGroup(); + if (group == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CallingView::UIViewGroup::new group error"); + return ; + } + group->SetPosition(0, 0); + group->Resize(VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION); // 454 : value + group->SetTouchable(true); + group->SetDraggable(true); + + dragListener = (UIView::OnDragListener*)OHOS::CalculatorPresenter::GetInstance(); + if (dragListener == nullptr) { + + return; + } + group->SetOnDragListener(dragListener); + AddViewToRootContainer(group); + + if(!button_init()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CallingView::UIViewGroup::new group error"); + return; + } + if(!Label_init()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CallingView::UIViewGroup::new group error"); + return; + } + + +} + + + + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/include/SaveBatPresenter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/include/SaveBatPresenter.h new file mode 100644 index 000000000..9b02bd006 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/include/SaveBatPresenter.h @@ -0,0 +1,59 @@ +/*** + * @Date: 2024-04-15 10:55:58 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-09-06 17:43:45 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveBatPresenter.h + */ + +#ifndef _SAVEBAT_PRESENTER_H +#define _SAVEBAT_PRESENTER_H + +#include "Presenter.h" +#include "saveele/include/SaveBatPresenter.h" +#include "saveele/include/SaveEleModel.h" +#include "saveele/include/SaveBatView.h" +#include "ModelListenerSample.h" +#include "MainModel.h" + +namespace OHOS +{ + class SaveBatView; + + class SaveBatPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener, + public UIView::OnLongPressListener, + public ModelListenerSample, + public UIView::OnTouchListener, + public RootView::OnKeyActListener + { + public: + SaveBatPresenter(); + virtual ~SaveBatPresenter(); + + void OnStart() override; + + static SaveBatPresenter *GetInstance(); + + void OnTickEvent() override; + void Notify() override {} + void ResetTickTimer(); + + void ExitView(void); + void Refresh_Back_View(); + + private: + bool OnPress(UIView &view, const PressEvent &event); + bool OnRelease(UIView &view, const ReleaseEvent &event); + bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 + + uint64_t startTime{0}; + int count = 3; // 初始计数 + int progressValue = 0; // 初始进度值 + uint16_t drag_x = 0; + uint16_t drag_y = 0; + }; + +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/include/SaveBatView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/include/SaveBatView.h new file mode 100644 index 000000000..79bbe43b1 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/include/SaveBatView.h @@ -0,0 +1,137 @@ +/*** + * @Date: 2024-04-15 10:55:58 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-19 15:07:03 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveBatView.h + */ +/*** + * @Date: 2024-04-15 10:55:58 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-17 10:30:26 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveBatView.h + */ + +#ifndef _SAVEBAT_VIEW_H +#define _SAVEBAT_VIEW_H + +//#include "BaseView.h" +#include "View.h" +#include +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_label_ext.h" +#include "components/ui_image_view.h" +#include "components/ui_button.h" +#include "components/ui_digital_clock.h" +#include "components/ui_box_progress.h" +#include "components/ui_circle_progress.h" + +#include "SaveBatPresenter.h" +#include +#include "components/ui_canvas.h" +#include "components/ui_scroll_view.h" +#include "components/ui_canvas_ext.h" +#include "components/ui_label_button.h" +#include "hal_tick.h" +namespace OHOS +{ + enum class countStage + { + STAGE_GRADUAL_CIRCLE = 0, + STAGE_COUNTING_DOWN, + STAGE_FADE_OUT, + STAGE_NONE + }; + class CountdownBackAnimatorCallback : public AnimatorCallback + { + public: + explicit CountdownBackAnimatorCallback(UICanvasExt *canvas) : canvas_(canvas) {} + ~CountdownBackAnimatorCallback() override {} + void Callback(UIView *view) override; + void NotifyStart(); + void CancelCountdown(); + void SetInfo(UILabel *label, int counts); + + private: + void CountingDown(); + void UpdatePath(int16_t start, int16_t end, bool needDrawCircle); + void UpdateLable(uint32_t curTime); + void CircleFadeOut(); + void GradualCircle(); + UICanvasExt *canvas_ = nullptr; + UILabel *label_ = nullptr; + bool updateText_ = false; + bool firstArc_ = false; + countStage stage_ = countStage::STAGE_NONE; + int16_t endAngle_ = 0; + int16_t easeDegree_ = 0; + uint16_t idleTime_ = 0; + int16_t counts_ = 0; + uint32_t lastTime_ = 0; + uint32_t degreePerSecond_ = 0; + uint32_t surplusDegree = 0; + }; + + class SaveBatPresenter; + class SaveBatView : public View + { + + public: + SaveBatView(); + virtual ~SaveBatView(); + static SaveBatView *GetInstance(void); + void updateClock(); + + void OnStart() override; + + void Init(); + void DeInit(); + UIView *GetView(); + + void Refresh_Dial_View(); + void Refresh_Back_View(); + + void InitBatteryView(); + void InitTimeView(); + void InitButtonView(); + void InitShowBackView(); + + void UpdateView(); + void StartCanvas(); + void StopCanvas(); + UILabel *GetCountlabel() + { + return countlabel; + } + UICircleProgress *GetBackprogress() + { + return backprogress; + } + + private: + UIView::OnDragListener *draglistener{nullptr}; + + SaveBatView(SaveBatView &&) = delete; + SaveBatView &operator=(SaveBatView &&) = delete; + /*省电界面*/ + UILabel *timelabel = nullptr; // 时间 + UILabel *datelabel = nullptr; // 日期标签 + UILabel *batterylabel = nullptr; // 电量标签 + UIBoxProgress *batteryprogress{nullptr}; // 电池进度条 + UIImageView *batteryiamge = nullptr; // 电池框图标 + UIButton *button_exit = nullptr; // 退出按键 + /*退出界面*/ + UILabel *curren_label{nullptr}; + UILabel *countlabel{nullptr}; + UIImageView *wathchiamge{nullptr}; + UICircleProgress *backprogress{nullptr}; + /*test*/ + CountdownBackAnimatorCallback *callBack_ = nullptr; + Animator *CountdownBackAnimator_ = nullptr; + UICanvasExt *canvas_ = nullptr; + UILabelButton *restart_ = nullptr; + UILabel *label_ = nullptr; + }; +} // namespace OHOS + +#endif // SLEEPDETAIL_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/include/SaveEleModel.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/include/SaveEleModel.h new file mode 100644 index 000000000..9ed43c922 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/include/SaveEleModel.h @@ -0,0 +1,43 @@ +/*** + * @Date: 2024-08-21 16:18:26 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-09-06 18:19:25 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveEleModel.h + */ +#ifndef SAVE_ELE_MODEL_H +#define SAVE_ELE_MODEL_H + +namespace OHOS +{ + class SaveEleModel + { + public: + // 获取单例实例 + static SaveEleModel *GetInstance(); + + // 获取充电状态 + bool GetChargeStatus(); + void SetChargeStatus(bool chargeStatus); + + // 设置视图状态 + bool GetViewState() const { return viewState; } + void SetViewState(bool state) { viewState = state; } + + // 设置退出状态 + bool GetBackState() const { return backStatus_; } + void SetBackState(bool state) { backStatus_ = state; } + + private: + SaveEleModel() = default; // 默认构造函数 + ~SaveEleModel() {} // 默认析构函数 + + SaveEleModel(const SaveEleModel &) = delete; // 禁止拷贝构造 + SaveEleModel &operator=(const SaveEleModel &) = delete; // 禁止赋值操作 + + bool chargeStatus_{false}; // 充电状态 + bool backStatus_{false}; // 退出状态 + bool viewState{false}; // 视图状态 + }; +} + +#endif // SAVE_ELE_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/include/SaveElePresenter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/include/SaveElePresenter.h new file mode 100644 index 000000000..6bc3ae99d --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/include/SaveElePresenter.h @@ -0,0 +1,41 @@ +/*** + * @Date: 2024-04-15 10:55:58 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-09 15:01:58 + * @FilePath: + * /FD230/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveElePresenter.h + */ +#ifndef _SAVEELE_PRESENTER_H +#define _SAVEELE_PRESENTER_H + +#include "Presenter.h" +#include "SaveEleView.h" + +namespace OHOS { +static constexpr const char *SAVEBUTTONOK = "buttonok"; +static constexpr const char *SAVEBUTTONNO = "buttonno"; + +class SaveEleView; +class SaveElePresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener, + public UIView::OnRotateListener, + public RootView::OnKeyActListener { +public: + SaveElePresenter(); + virtual ~SaveElePresenter(); + + void OnStart() override; + + static SaveElePresenter *GetInstance(); + +private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 + bool OnRotateEnd(UIView &view, const RotateEvent &event); +}; +} // namespace OHOS + +#endif // SLEEPDETAIL_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/include/SaveEleView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/include/SaveEleView.h new file mode 100644 index 000000000..dde0ca76b --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/include/SaveEleView.h @@ -0,0 +1,50 @@ +#ifndef _SAVEELE_VIEW_H +#define _SAVEELE_VIEW_H + +//#include "BaseView.h" +#include "View.h" +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_label_ext.h" +#include "components/ui_image_view.h" +#include "components/ui_button.h" + +#include "components/ui_scroll_view.h" +#include "uicomponents/UIComponents.h" +#include "SaveElePresenter.h" + +#include "SaveElePresenter.h" +namespace OHOS +{ + class SaveElePresenter; + class SaveEleView : public View + { + + public: + SaveEleView(); + virtual ~SaveEleView(); + static SaveEleView *GetInstance(void); + + void OnStart() override; + void InitView(); + void DeInit(); + + private: + UIView::OnDragListener *draglistener{nullptr}; + + + SaveEleView(SaveEleView &&) = delete; + SaveEleView &operator=(SaveEleView &&) = delete; + + UILabelExt *labeltitle = nullptr; + UILabelExt *labelnote = nullptr; + UILabelExt *labelkown = nullptr; + UIButton *buttonok = nullptr; + UIButton *buttonno = nullptr; + UIImageView *iamgeicon = nullptr; + UIScrollView *scrollview_ = nullptr; + UIScrollView *SaveEleView_ = nullptr; + + }; +} // namespace OHOS +#endif // SaveEle_PRESENTER_H diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveBatPresenter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveBatPresenter.cpp new file mode 100644 index 000000000..c4be16f9d --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveBatPresenter.cpp @@ -0,0 +1,148 @@ + +#include "AppViewIDs.h" +#include "KeyInputListener.h" +#include "MainModel.h" +#include "NativeAbility.h" +#include "common/key_code.h" +#include "cmsis_os.h" +//#include "battery_hal.h" +#include "custom_utils.h" +#include "saveele/include/SaveBatPresenter.h" +#include "saveele/include/SaveBatView.h" +#include "saveele/include/SaveEleModel.h" +#include "string.h" +#include "time.h" +#include "NativeRegisterManager.h" + + +namespace OHOS { + + REGIST_SLICE(VIEW_SAVEBAT, SaveBatView, SaveBatPresenter); + +// 当前Presenter属性实例化的内存指针 +static SaveBatPresenter *g_pSaveBatPresenter = nullptr; + +// 时间间隔宏定义(以毫秒为单位) +#define ONE_SECOND 1000 +#define TWO_SECONDS 2000 +#define THREE_SECONDS 3000 +#define TIME_THRESHOLD 3000 + +// 判断时间条件的宏 +#define IS_TIME_MATCH(startTime, current_time, interval) \ + ((startTime != 0) && ((current_time - startTime) >= (interval))) +#define IS_TIME_EXCEED(startTime, current_time) \ + ((startTime != 0) && ((current_time - startTime) > (TIME_THRESHOLD))) + +SaveBatPresenter::SaveBatPresenter() { g_pSaveBatPresenter = this; } + +SaveBatPresenter::~SaveBatPresenter() { g_pSaveBatPresenter = nullptr; } + +SaveBatPresenter *SaveBatPresenter::GetInstance() { + return g_pSaveBatPresenter; +} + +/* + void enable_drag(uint8_t direction, uint8_t enable); + void set_drag_limit(uint8_t direction, uint16_t limit); + uint16_t get_drag_limit(uint8_t direction); +*/ +void SaveBatPresenter::OnStart() { + Presenter::OnStart(); + // 1.获取原drag + #ifdef CUSTOM_UTILS + drag_x = get_drag_limit(0); + drag_y = get_drag_limit(1); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "drag_x:%d,drag_y:%d", drag_x, drag_y); + // 2.设置drag + enable_drag(0, 0); + enable_drag(1, 0); + #endif +} + + + +bool SaveBatPresenter::OnPress(UIView &view, const PressEvent &event) { + if (strcmp(view.GetViewId(), "button_exit") == 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "进行按下"); + if (SaveEleModel::GetInstance()->GetViewState() == false) { + SaveEleModel::GetInstance()->SetViewState(true); + SaveBatView::GetInstance()->UpdateView(); + SaveBatView::GetInstance()->StartCanvas(); + } + } + return true; +} +bool SaveBatPresenter::OnRelease(UIView &view, const ReleaseEvent &event) { + if (strcmp(view.GetViewId(), "button_exit") == 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "进行松开"); + if (SaveEleModel::GetInstance()->GetViewState() == true) { + SaveBatView::GetInstance()->StopCanvas(); + SaveEleModel::GetInstance()->SetViewState(false); + SaveBatView::GetInstance()->UpdateView(); + } + } + return true; +} +void SaveBatPresenter::ExitView(void) { + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); +} + +void SaveBatPresenter::OnTickEvent() { + /*省电表盘界面*/ + if (SaveEleModel::GetInstance()->GetViewState() == false) { + SaveBatView::GetInstance()->Refresh_Dial_View(); + } + /*退出判断*/ + bool chargeStatus = SaveEleModel::GetInstance()->GetChargeStatus(); + bool backState = SaveEleModel::GetInstance()->GetBackState(); + if (chargeStatus || backState) { + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, + "退出省电模式 Charge_Status: %d, Back_State: %d", + chargeStatus, backState); + SaveEleModel::GetInstance()->SetBackState(false); + ExitView(); + } +} +void SaveBatPresenter::ResetTickTimer(void) { + startTime = osKernelGetTick2ms(); +} +/* 更新退出UI */ +void SaveBatPresenter::Refresh_Back_View() { + if (SaveBatView::GetInstance()->GetCountlabel() == nullptr || + SaveBatView::GetInstance()->GetBackprogress() == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "Refresh_Back_View: countlabel or backprogress is null."); + return; + } + + if (count > 0) // 确保不会减少到负数 + { + // 每次调用时尝试更新进度值 + progressValue++; + + // 更新计数并检查进度值 + if (progressValue == 50 || progressValue == 75 || progressValue == 100) { + count--; + SaveBatView::GetInstance()->GetCountlabel()->SetText( + std::to_string(count).c_str()); + } + + // 根据最大值进行检查以避免进度条越界 + if (progressValue >= 100) // 假设进度最大值为100 + { + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); + } else { + SaveBatView::GetInstance()->GetBackprogress()->SetValue(progressValue); + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "Refresh_Back_View: 当前计数: %d, 当前进度值: %d", count, + progressValue); + } +} +bool SaveBatPresenter::OnKeyAct(UIView &view, const KeyEvent &event) { + /*消耗按键事件*/ + return true; +} +} // namespace OHOS diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveBatView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveBatView.cpp new file mode 100644 index 000000000..96410bfd5 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveBatView.cpp @@ -0,0 +1,855 @@ + + +#include "saveele/include/SaveBatView.h" +#include "saveele/include/SaveEleModel.h" + +#include "common/image_cache_manager.h" +#include "UiConfig.h" +#include "ui_resource_image.h" +#include +#include +#include +#include +//#include "battery_hal.h" +#include "string" +#include "custom_utils.h" +#include "UiConfig.h" +#include "wearable_log.h" + +#include "custom_runtime.h" +#include "ConfigModel.h" +#include "languagecode/LanguageInit.h" + +#define ANIMATION_TEST 0 +extern "C" +{ + void uapi_exit_power_saving_mode(void); + void uapi_enter_power_saving_mode(void); +} + +std::string Cnweekday[] = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"}; +std::string Enweekday[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; + +static constexpr const char *WHITE_BATTERY = "/user/res/Battery/Battery_White.bin"; +static constexpr const char *SAVE_BUTTON = "/user/res/Save_Ele/finger.bin"; +static constexpr const char *BACK_BUTTON = "/user/res/Save_Ele/finger2.bin"; +static constexpr const char *SAVE_WATHCH = "/user/res/Save_Ele/wathch.bin"; + +namespace OHOS +{ + /*动画类实现*/ + const static int16_t CENTER_X = 233; + const static int16_t CENTER_Y = 233; + const static int16_t LABEL_X = 140; + const static int16_t LABEL_Y = 170; + const static int16_t RADIUS = 90; // 半径 90 + const static int16_t STROKE_WIDTH = 20; + const static int16_t CIRCLE_BASE_WIDTH = 4; + const static uint32_t LIGHT_GREEN = 0xff007700; + static const uint16_t LABEL_FONT_SIZE = 80; + static const uint16_t ANIMATE_TIME = 500; + static const uint16_t SECOND_TO_MINISECOND = 1000; + static const uint16_t CIRCLE_FADE_OUT = 200; + static const uint16_t DEGREES_PER_CIRCLE = 360; + void CountdownBackAnimatorCallback::Callback(UIView *view) + { + // 根据当前阶段调用相应的功能,控制动画状态 + switch (stage_) + { + case countStage::STAGE_GRADUAL_CIRCLE: + { + // 处理渐变圆圈绘制 + GradualCircle(); + break; + } + case countStage::STAGE_COUNTING_DOWN: + { + // 处理倒计时逻辑 + CountingDown(); + break; + } + case countStage::STAGE_FADE_OUT: + { + // 处理圆圈淡出效果 + CircleFadeOut(); + break; + } + default: + break; + } + } + + void CountdownBackAnimatorCallback::CircleFadeOut() + { + // 计算当前时间与上次更新时间的差值 + uint32_t diffTime = HALTick::GetInstance().GetTime() - lastTime_; + + // 如果尚未达到空闲时间,则什么也不做 + if (diffTime < idleTime_) + { + return; + } + + // 清空画布以准备绘制 + canvas_->Clear(); + + // 计算当前的圆圈宽度 + uint32_t curTime = diffTime - idleTime_; + uint16_t width; + + // 判断是否已经达到淡出持续时间 + if (curTime >= CIRCLE_FADE_OUT) + { + curTime = CIRCLE_FADE_OUT; // 限制为最大淡出时间 + stage_ = countStage::STAGE_NONE; // 设置为无状态 + } + + // 使用缓动方程计算当前宽度 + width = EasingEquation::QuadEaseInOut(STROKE_WIDTH, CIRCLE_BASE_WIDTH, curTime, CIRCLE_FADE_OUT); + + // 绘制中心圆圈 + Point center = {CENTER_X, CENTER_Y}; + ColorType lightGreen; + lightGreen.full = LIGHT_GREEN; + PaintExt paint; + paint.SetStyle(Paint::PaintStyle::STROKE_STYLE); + paint.SetCapType(CAP_ROUND); + paint.SetAntialiased(true); + paint.SetStrokeColor(lightGreen); + paint.SetStrokeWidth(width); + canvas_->DrawCircle(center, RADIUS, paint); + + // 更新标签的字体大小和透明度 + uint16_t fontSize = LABEL_FONT_SIZE * width / STROKE_WIDTH; // 根据笔画宽度调整字体大小 + uint16_t opa = OPA_OPAQUE * width / STROKE_WIDTH; // 根据笔画宽度调整透明度 + if (stage_ == countStage::STAGE_NONE) + { + opa = OPA_TRANSPARENT; // 如果处于无状态,设置为完全透明 + } + + label_->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, fontSize); + label_->SetStyle(STYLE_TEXT_OPA, opa); // 更新标签样式 + } + + void CountdownBackAnimatorCallback::UpdateLable(uint32_t curTime) + { + char buf[2] = {0}; // 字符缓冲区,用于格式化标签文本 + uint16_t fontSize; // 字体大小 + uint16_t opa; // 透明度 + + // 前半段动画,字体逐渐变小 + if (curTime < ANIMATE_TIME / 2) + { + fontSize = LABEL_FONT_SIZE - LABEL_FONT_SIZE * curTime * 2 / ANIMATE_TIME; // 计算当前字体大小 + opa = OPA_OPAQUE * fontSize / LABEL_FONT_SIZE; // 计算当前透明度 + if (firstArc_) + { + fontSize = fontSize / 2; // 如果是第一弧,字体设置为一半大小 + } + } + else + { + // 后半段动画,字体逐渐增大 + fontSize = LABEL_FONT_SIZE * curTime * 2 / ANIMATE_TIME - LABEL_FONT_SIZE; + opa = OPA_OPAQUE * fontSize / LABEL_FONT_SIZE; + + // 更新标签文本 + if (updateText_) + { + if (sprintf_s(buf, sizeof(buf), "%u", (endAngle_ + easeDegree_) / degreePerSecond_) < 0) + { + return; // 如果 sprintf_s 出错,返回 + } + label_->SetText(buf); // 设置标签文本为当前倒计时数字 + updateText_ = false; // 更新文本之后将标志置为false + } + } + + // 更新标签的字体和样式 + label_->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, fontSize); + label_->SetStyle(STYLE_TEXT_OPA, opa); + } + + void CountdownBackAnimatorCallback::UpdatePath(int16_t start, int16_t end, bool needDrawCircle) + { + // 计算绘制的圆心和颜色 + Point center = {CENTER_X, CENTER_Y}; + ColorType lightGreen; + lightGreen.full = LIGHT_GREEN; + PaintExt paint; + paint.SetStyle(Paint::PaintStyle::STROKE_STYLE); + paint.SetStrokeWidth(STROKE_WIDTH); + paint.SetCapType(CAP_ROUND); + paint.SetAntialiased(true); + paint.SetStrokeColor(lightGreen); + + // 清空画布 + canvas_->Clear(); + // 如果需要绘制基础圆圈,则绘制 + if (needDrawCircle) + { + canvas_->DrawCircle(center, RADIUS, paint); + } + + // 如果起始角度与结束角度不相同,则绘制弧线 + if (start != end) + { + paint.SetStrokeColor(Color::Green()); // 设置弧线颜色为绿色 + // 如果起始角和结束角相差完整的一圈,则绘制完整的圆圈 + if (end - start == DEGREES_PER_CIRCLE) + { + canvas_->DrawCircle(center, RADIUS, paint); + } + else + { + // 绘制从起始角到结束角 + // 绘制从起始角到结束角的弧线 + canvas_->DrawArc(center, RADIUS, start, end, paint); + } + } + } + + void CountdownBackAnimatorCallback::CountingDown() + { + // 计算当前时间与上次更新时间的差值 + uint32_t diffTime = HALTick::GetInstance().GetTime() - lastTime_; + + // 如果时间差达到1秒,则更新倒计时 + if (diffTime >= SECOND_TO_MINISECOND) + { + lastTime_ = HALTick::GetInstance().GetTime(); // 更新最后时间 + // 判断是否是第一次绘制弧线 + if (endAngle_ == DEGREES_PER_CIRCLE) + { + firstArc_ = true; // 如果是第一次,设置标志 + } + else + { + firstArc_ = false; // 否则,设置为非第一次 + } + // 更新路径和标签 + UpdatePath(0, endAngle_, true); + UpdateLable(0); + + // 如果倒计时结束,切换到淡出阶段 + if (endAngle_ == 0) + { + stage_ = countStage::STAGE_FADE_OUT; + idleTime_ = SECOND_TO_MINISECOND - CIRCLE_FADE_OUT; // 设置空闲时间 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "倒计时结束"); + OHOS::SaveEleModel::GetInstance()->SetBackState(true); // 进行界面弹出 + return; + } + + // 更新结束角度和缓动角度 + easeDegree_ = degreePerSecond_; + endAngle_ -= degreePerSecond_; // 减少结束角度 + // 如果结束角度小于等于剩余角度,则重置结束角度 + if (endAngle_ <= surplusDegree) + { + endAngle_ = 0; + easeDegree_ += surplusDegree; // 增加缓动角度 + } + updateText_ = true; // 标记需要更新文本 + } + else if (diffTime >= idleTime_) + { + // 如果时间差超过空闲时间,更新路径和标签 + uint32_t curTime = diffTime - idleTime_; + int16_t arcCurr = EasingEquation::QuadEaseInOut(0, easeDegree_, curTime, ANIMATE_TIME); + UpdatePath(0, endAngle_ + easeDegree_ - arcCurr, true); + UpdateLable(curTime); + } + } + + void CountdownBackAnimatorCallback::GradualCircle() + { + // 计算当前时间与上次更新时间的差值 + uint32_t diffTime = HALTick::GetInstance().GetTime() - lastTime_; + + // 如果时间差达到1秒,则切换到倒计时阶段 + if (diffTime >= SECOND_TO_MINISECOND) + { + stage_ = countStage::STAGE_COUNTING_DOWN; // 切换阶段 + idleTime_ = SECOND_TO_MINISECOND - ANIMATE_TIME; // 设置空闲时间 + } + else if (diffTime >= idleTime_) + { + // 如果时间差超过空闲时间,绘制渐变圆圈 + uint32_t curTime = diffTime - idleTime_; + int16_t arcCurr = EasingEquation::QuadEaseInOut(0, DEGREES_PER_CIRCLE, + curTime, SECOND_TO_MINISECOND - idleTime_); + UpdatePath(180, arcCurr + 180, false); // 从180度开始绘制 + } + } + + void CountdownBackAnimatorCallback::SetInfo(UILabel *label, int counts) + { + // 设置标签和计数值 + counts_ = counts; // 记录倒计时的总次数 + label_ = label; // 记录UILabel对象 + } + + void CountdownBackAnimatorCallback::NotifyStart() + { + // 初始化倒计时动画的状态 + stage_ = countStage::STAGE_GRADUAL_CIRCLE; // 设置为渐变圆圈阶段 + endAngle_ = DEGREES_PER_CIRCLE; // 设置结束角度为完整一圈 + idleTime_ = 200; // 设置初始空闲时间 + degreePerSecond_ = DEGREES_PER_CIRCLE / counts_; // 计算每秒减少的角度 + surplusDegree = DEGREES_PER_CIRCLE - degreePerSecond_ * counts_; // 计算剩余角度 + lastTime_ = HALTick::GetInstance().GetTime(); // 记录当前时间 + + // 初始化标签文本和样式 + label_->SetText(" "); + label_->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, LABEL_FONT_SIZE / 2); // 设置字体为一半大小 + label_->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); // 设置标签为不透明 + } + + void CountdownBackAnimatorCallback::CancelCountdown() + { + // 设置阶段为淡出 + stage_ = countStage::STAGE_FADE_OUT; + + // 重置时间以立即开始淡出 + lastTime_ = HALTick::GetInstance().GetTime(); // 记录当前时间 + idleTime_ = 0; // 设置空闲时间为零,以跳过任何等待时间 + + endAngle_ = 0; // 设置结束角度为0,表示取消倒计时 + } + + static SaveBatView *g_pSaveBatView{nullptr}; + + SaveBatView::SaveBatView() + { + /*开启省电模式*/ + uapi_enter_power_saving_mode(); + + g_pSaveBatView = this; + } + + + SaveBatView::~SaveBatView() + { + /* 关闭省电模式 */ + uapi_exit_power_saving_mode(); + + // UIViewGroup *tmpGroup = dynamic_cast(container_); + // UIViewGroup::RemoveAndDeleteAllRecursively(tmpGroup); + + // 释放所有动态分配的成员变量 + if (timelabel) { + delete timelabel; + timelabel = nullptr; + } + if (datelabel) { + delete datelabel; + datelabel = nullptr; + } + if (batterylabel) { + delete batterylabel; + batterylabel = nullptr; + } + if (batteryprogress) { + delete batteryprogress; + batteryprogress = nullptr; + } + if (batteryiamge) { + delete batteryiamge; + batteryiamge = nullptr; + } + if (button_exit) { + delete button_exit; + button_exit = nullptr; + } + + // 退出界面的成员变量 + if (curren_label) { + delete curren_label; + curren_label = nullptr; + } + if (countlabel) { + delete countlabel; + countlabel = nullptr; + } + if (wathchiamge) { + delete wathchiamge; + wathchiamge = nullptr; + } + if (backprogress) { + delete backprogress; + backprogress = nullptr; + } + + // 测试相关的成员变量 + if (CountdownBackAnimator_) { + CountdownBackAnimator_->Stop(); + } + if (callBack_) { + delete callBack_; + callBack_ = nullptr; + } + + delete CountdownBackAnimator_; + CountdownBackAnimator_ = nullptr; + + if (canvas_) { + delete canvas_; + canvas_ = nullptr; + } + if (restart_) { + delete restart_; + restart_ = nullptr; + } + + if (label_) { + delete label_; + label_ = nullptr; + } + + // 将全局指针设为 nullptr + g_pSaveBatView = nullptr; + } + + SaveBatView *SaveBatView::GetInstance() + { + return g_pSaveBatView; + } + + /* 更新主界面数据 */ + void SaveBatView::Refresh_Dial_View() + { + /* + 日期样式 04-22 周五 + 时间样式 09:10 + */ + if (timelabel == nullptr || datelabel == nullptr || batterylabel == nullptr || batteryprogress == nullptr) + return; + + // 获取当前时间 + time_t seconds; + time(&seconds); + struct tm pTM; + localtime_r(&seconds, &pTM); + + // 解析时间 + int hour = pTM.tm_hour; + int minute = pTM.tm_min; + int day = pTM.tm_mday; + int month = pTM.tm_mon + 1; // 月份范围 [1, 12] + std::string weekStr; + if (ConfigModel::GetInstance()->GetLanguage() == ZH_CN) + weekStr = Cnweekday[pTM.tm_wday]; + else + weekStr = Enweekday[pTM.tm_wday]; + + // 构建日期和时间字符串 + std::string dateStr = + (month < 10 ? "0" : "") + std::to_string(month) + "-" + + (day < 10 ? "0" : "") + std::to_string(day) + " " + weekStr; + + //需要判断显示的格式 + if (uapi_dev_runtime_get_time_hour_show_model() == 12) + { + if (pTM.tm_hour > 12) + hour = pTM.tm_hour - 12 ; + } + + std::string stringtime = + (hour < 10 ? "0" : "") + std::to_string(hour) + ":" + + (minute < 10 ? "0" : "") + std::to_string(minute); + + // 获取电量值 + float voltage = 0.0F; + //uint8_t value = battery_get_voltage(&voltage); + uint8_t value = 0; + + + // 更新界面组件 + timelabel->SetText(stringtime.c_str()); + datelabel->SetText(dateStr.c_str()); + batterylabel->SetText((std::to_string(value) + "%").c_str()); + batteryprogress->SetValue(value); + } + + void SaveBatView::InitBatteryView() + { + // 创建电池框图像 + batteryiamge = new UIImageView(); + if (!batteryiamge) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batteryiamge creation failed"); + return; + } + + // 创建电池进度条 + batteryprogress = new UIBoxProgress(); + if (!batteryprogress) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batteryprogress creation failed"); + return; + } + + // 创建电池标签 + batterylabel = new UILabel(); + if (!batterylabel) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batterylabel creation failed"); + return; + } + + // 设置位置 + batteryiamge->SetPosition(176, 52, 100, 100); + batteryiamge->SetSrc(WHITE_BATTERY); + + batteryprogress->SetPosition(182, 58, 30, 18); + batteryprogress->SetStyle(STYLE_BORDER_RADIUS, 20); + batteryprogress->SetViewId("batteryprogress"); + batteryprogress->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + + batterylabel->SetPosition(228, 54, 200, 60); + batterylabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 26); + batterylabel->SetTextColor(Color::White()); + batteryprogress->SetForegroundStyle(STYLE_BACKGROUND_COLOR, 0xffffc300); + + AddViewToRootContainer(batteryiamge); + AddViewToRootContainer(batterylabel); + AddViewToRootContainer(batteryprogress); + } + void SaveBatView::InitTimeView() + { + /*时间time*/ + timelabel = new UILabel(); + if (timelabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "timelabel creation failed"); + return; + } + timelabel->SetPosition(0, 148); + timelabel->Resize(466, 100); + timelabel->SetViewId("label1"); + timelabel->SetStyle(STYLE_TEXT_FONT, 100); + timelabel->SetText("11:00"); + timelabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + timelabel->SetTextColor(Color::GetColorFromRGBA(0x49, 0xef, 0x13, 0xff)); + timelabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + timelabel->SetRollSpeed(0); + timelabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 100); + AddViewToRootContainer(timelabel); + + /*日期*/ + datelabel = new UILabel(); + if (datelabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "datelabel creation failed"); + return; + } + datelabel->SetPosition(83, 258); + datelabel->Resize(300, 60); + datelabel->SetViewId("label2"); + datelabel->SetStyle(STYLE_TEXT_FONT, 30); + + // datelabel->SetText("04-22 周五"); + datelabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + datelabel->SetTextColor(Color::GetColorFromRGBA(0x66, 0x66, 0x66, 0xff)); + datelabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + datelabel->SetRollSpeed(0); + datelabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30); + AddViewToRootContainer(datelabel); + } + void SaveBatView::InitButtonView() + { + // 初始化按键 + button_exit = new UIButton(); + if (button_exit == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "button_exit creation failed"); + return; + } + button_exit->SetPosition(204, 350); + button_exit->Resize(100, 100); + button_exit->SetViewId("button_exit"); + button_exit->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + button_exit->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + + button_exit->SetImageSrc(SAVE_BUTTON, SAVE_BUTTON); + button_exit->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED); + + button_exit->SetOnTouchListener(presenter_); + AddViewToRootContainer(button_exit); + } + void SaveBatView::InitShowBackView() + { + // 时间 + time_t seconds; + time(&seconds); + struct tm pTM; + 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); + + curren_label = new UILabel(); + if (curren_label == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "curren_label creation failed"); + return; + } + curren_label->SetPosition(181, 52); + curren_label->Resize(200, 60); + curren_label->SetViewId("label4"); + curren_label->SetStyle(STYLE_TEXT_FONT, 40); + curren_label->SetText(stringtime.c_str()); + curren_label->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + curren_label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + curren_label->SetRollSpeed(0); + curren_label->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 40); + AddViewToRootContainer(curren_label); + curren_label->SetVisible(false); +#if ANIMATION_TEST + // 圆形进度条 + backprogress = new UICircleProgress(); + if (backprogress == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "backprogress creation failed"); + return; + } + backprogress->SetPosition(143, 143); + backprogress->Resize(183, 186); + backprogress->SetViewId("circleProgress1"); + backprogress->SetStyle(STYLE_BACKGROUND_OPA, 0x00); // 确保背景透明 + backprogress->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, 0x00000000); // 背景颜色设置为完全透明 + backprogress->SetBackgroundStyle(STYLE_LINE_WIDTH, 20); + backprogress->SetForegroundStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + backprogress->SetForegroundStyle(STYLE_BORDER_COLOR, 0xff000000); + backprogress->SetForegroundStyle(STYLE_LINE_COLOR, 0xff18ef05); + backprogress->SetForegroundStyle(STYLE_LINE_WIDTH, 20); + backprogress->SetCenterPosition(92, 93); + backprogress->SetRadius(90); + backprogress->SetEndAngle(359); + backprogress->SetValue(0); + container_->Add(backprogress); + backprogress->SetVisible(false); + + // 手表image + wathchiamge = new UIImageView(); + if (wathchiamge == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "wathchiamge creation failed"); + return; + } + wathchiamge->SetPosition(191, 182); + wathchiamge->Resize(100, 100); + wathchiamge->SetViewId("image1"); + wathchiamge->SetSrc(SAVE_WATHCH); + container_->Add(wathchiamge); + wathchiamge->SetVisible(false); + + // 倒计时 + countlabel = new UILabel(); + if (countlabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "countlabel creation failed"); + return; + } + countlabel->SetPosition(221, 212); + countlabel->Resize(200, 60); + countlabel->SetViewId("label3"); + countlabel->SetStyle(STYLE_TEXT_FONT, 40); + countlabel->SetText("3"); + countlabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + countlabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + countlabel->SetRollSpeed(0); + countlabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 40); + container_->Add(countlabel); + countlabel->SetVisible(false); +#else + if (canvas_ == nullptr) + { + canvas_ = new UICanvasExt(); + } + canvas_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + canvas_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + AddViewToRootContainer(canvas_); + canvas_->SetVisible(false); + + if (label_ == nullptr) + { + label_ = new UILabel(); + } + label_->SetPosition(LABEL_X, LABEL_Y, 180, 120); + label_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + AddViewToRootContainer(label_); + label_->SetVisible(false); + + PaintExt paint; + ColorType lightGreen; + lightGreen.full = LIGHT_GREEN; + paint.SetStyle(Paint::PaintStyle::STROKE_STYLE); + paint.SetStrokeWidth(CIRCLE_BASE_WIDTH); + paint.SetAntialiased(true); + paint.SetStrokeColor(lightGreen); + canvas_->DrawCircle({CENTER_X, CENTER_Y}, RADIUS, paint); + + callBack_ = new CountdownBackAnimatorCallback(canvas_); + if (callBack_ == nullptr) + { + GRAPHIC_LOGE("CallBack new fail"); + return; + } + CountdownBackAnimator_ = new Animator(callBack_, canvas_, 0, true); + if (CountdownBackAnimator_ == nullptr) + { + delete callBack_; + callBack_ = nullptr; + GRAPHIC_LOGE("Animator new fail"); + return; + } + CountdownBackAnimator_->Start(); + callBack_->SetInfo(label_, 3); // 3: countdown numbers +#endif + } + + // 更新当前界面状态 + void SaveBatView::UpdateView() + { + bool state = SaveEleModel::GetInstance()->GetViewState(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UpdateView state %d", state); + + // 检查每个组件是否为空,并记录具体信息 + if (timelabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "timelabel is null"); + return; + } + if (datelabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "datelabel is null"); + return; + } + if (batterylabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batterylabel is null"); + return; + } + if (batteryprogress == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batteryprogress is null"); + return; + } + if (batteryiamge == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batteryiamge is null"); + return; + } + if (curren_label == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "curren_label is null"); + return; + } +#if ANIMATION_TEST + if (countlabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "countlabel is null"); + return; + } + if (wathchiamge == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "wathchiamge is null"); + return; + } + if (backprogress == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "backprogress is null"); + return; + } +#endif + if (button_exit == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "button_exit is null"); + return; + } + + // 显示/隐藏原界面组件 + bool showPrimaryView = !state; + timelabel->SetVisible(showPrimaryView); + datelabel->SetVisible(showPrimaryView); + batterylabel->SetVisible(showPrimaryView); + batteryprogress->SetVisible(showPrimaryView); + batteryiamge->SetVisible(showPrimaryView); + +#if ANIMATION_TEST + // 初始化计数器 + int count = 3; + int progressValue = 0; + countlabel->SetText(std::to_string(count).c_str()); + backprogress->SetValue(progressValue); + + /* 退出界面 */ + curren_label->SetVisible(state); + countlabel->SetVisible(state); + wathchiamge->SetVisible(state); + backprogress->SetVisible(state); + +#else + /* 退出界面 */ + curren_label->SetVisible(state); + + // 显示当前时间 + time_t seconds; + time(&seconds); + struct tm pTM; + 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); + curren_label->SetText(stringtime.c_str()); + label_->SetVisible(state); + canvas_->SetVisible(state); + +#endif + + // 设置退出按钮图像 + const char *buttonImage = state ? BACK_BUTTON : SAVE_BUTTON; + button_exit->SetImageSrc(buttonImage, buttonImage); + } + + /*动画的控制*/ + void SaveBatView::StartCanvas() + { + callBack_->NotifyStart(); + } + void SaveBatView::StopCanvas() + { + callBack_->CancelCountdown(); + } + + void SaveBatView::OnStart() + { + + + GetRootContainer()->SetPosition(0, 0); + GetRootContainer()->SetWidth(Screen::GetInstance().GetWidth()); + GetRootContainer()->SetHeight(Screen::GetInstance().GetHeight()); + GetRootContainer()->SetTouchable(true); + GetRootContainer()->SetDraggable(true); + + InitBatteryView(); + InitTimeView(); + InitButtonView(); + InitShowBackView(); + + Draw(); + + //SetContainerView(container_); + //RootView::GetInstance()->SetOnKeyActListener(presenter_); + } + + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveEleModel.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveEleModel.cpp new file mode 100644 index 000000000..990c50097 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveEleModel.cpp @@ -0,0 +1,20 @@ + +#include "saveele/include/SaveEleModel.h" + +namespace OHOS +{ + + SaveEleModel *SaveEleModel::GetInstance(void) + { + static SaveEleModel instance; + return &instance; + } + bool SaveEleModel::GetChargeStatus() + { + return chargeStatus_; + } + void SaveEleModel::SetChargeStatus(bool chargeStatus) + { + chargeStatus_ = chargeStatus; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveElePresenter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveElePresenter.cpp new file mode 100644 index 000000000..8c4460c1f --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveElePresenter.cpp @@ -0,0 +1,83 @@ + +#include "AppViewIDs.h" +#include "KeyInputListener.h" +#include "NativeAbility.h" +#include "common/key_code.h" +#include "components/ui_label_ext.h" +#include "custom_utils.h" +#include "ui_resource_string.h" + +#include "gfx_utils/mem_check.h" +#include "saveele/include/SaveElePresenter.h" +#include "vibrator_service.h" +#include "NativeRegisterManager.h" + + +namespace OHOS { + + REGIST_MENU_PRO(VIEW_SAVEELE, SaveEleView, SaveElePresenter, + PNG_APPLIST_BRIGHTNESSLEVEL_IMAGE_BIG, PNG_APPLIST_BRIGHTNESSLEVEL_IMAGE, PNG_APPLIST_BRIGHTNESSLEVEL_IMAGE, "省电模式", STR_POWER_SAVE_MODE); + +// 当前Presenter属性实例化的内存指针 +static SaveElePresenter *g_pSaveElePresenter = nullptr; + +SaveElePresenter::SaveElePresenter() { +#ifdef MEM_CHECK + MemCheck::GetInstance()->EnableLeakCheck(true); +#endif + g_pSaveElePresenter = this; +} + +SaveElePresenter::~SaveElePresenter() { +#ifdef MEM_CHECK + MemCheck::GetInstance()->EnableLeakCheck(false); +#endif + g_pSaveElePresenter = nullptr; +} + +SaveElePresenter *SaveElePresenter::GetInstance() { + + return g_pSaveElePresenter; +} + +void SaveElePresenter::OnStart() { Presenter::OnStart(); } + + +bool SaveElePresenter::OnDrag(UIView &view, const DragEvent &event) { + + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && + (event.GetDeltaX() > 20) && + (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().Back(); + } + UNUSED(view); + return true; +} + +bool SaveElePresenter::OnClick(UIView &view, const ClickEvent &event) { + if (strcmp(view.GetViewId(), SAVEBUTTONNO) == 0) { + NativeAbility::GetInstance().Back(); + } + if (strcmp(view.GetViewId(), SAVEBUTTONOK) == 0) { + NativeAbility::GetInstance().ChangeSlice(VIEW_SAVEBAT); + } + return true; +} +bool SaveElePresenter::OnKeyAct(UIView &view, const KeyEvent &event) { + unsigned short keyID = event.GetKeyId(); + unsigned short keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && + keyState == 1 && uapi_get_screen_state() == 0) { + NativeAbility::GetInstance().Back(); + } + return true; +} + +bool SaveElePresenter::OnRotateEnd(UIView &view, const RotateEvent &event) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "VolumeSliderEventListener::OnRotateEnd"); +// ui_api_vibrate_once_func(); + return true; +} +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveEleView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveEleView.cpp new file mode 100644 index 000000000..2bf54c6ad --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveEleView.cpp @@ -0,0 +1,149 @@ +/*** + * @Date: 2024-04-15 10:55:58 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-09 14:41:32 + * @FilePath: + * /FD230/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveEleView.cpp + */ + +#include "saveele/include/SaveEleView.h" +#include "saveele/include/SaveElePresenter.h" + +#include "UiConfig.h" +#include "common/image_cache_manager.h" +#include "components/ui_button.h" +#include "components/ui_scroll_view.h" +#include "ui_resource_image.h" +#include "ui_resource_string.h" +#include "uicomponents/UIComponents.h" +#include "components/ui_scroll_view.h" + +namespace OHOS { + +static SaveEleView *g_pSaveEleView{nullptr}; +static const uint32_t BACK_GROUND_COLOR = 0xfff6f6f6; + +static constexpr char *iconImgPath = "/user/res/Save_Ele/SaveEle.bin"; +static constexpr char *butnoImgPath = "/user/res/Save_Ele/Save_Error.bin"; +static constexpr char *butokImgPath = "/user/res/Save_Ele/Save_Right.bin"; + +SaveEleView::SaveEleView() { g_pSaveEleView = this; } + +SaveEleView::~SaveEleView() { + + // UIViewGroup *tmpGroup = dynamic_cast(container_); + // UIViewGroup::RemoveAndDeleteAllRecursively(tmpGroup); + + if (scrollview_ != nullptr) { + scrollview_->RemoveAll(); + delete scrollview_; + scrollview_ = nullptr; + } + RootView::GetInstance()->RemoveAll(); + + if (labeltitle) { + delete labeltitle; + labeltitle = nullptr; + } + if (labelnote) { + delete labelnote; + labelnote = nullptr; + } + if (labelkown) { + delete labelkown; + labelkown = nullptr; + } + if (iamgeicon) { + delete iamgeicon; + iamgeicon = nullptr; + } + if (buttonno) { + delete buttonno; + buttonno = nullptr; + } + if (buttonok) { + delete buttonok; + buttonok = nullptr; + } + + g_pSaveEleView = nullptr; +} + +SaveEleView *SaveEleView::GetInstance() { return g_pSaveEleView; } + +void SaveEleView::InitView() { + + SaveEleView_ = new UIScrollView(); + SaveEleView_->SetPosition(0, 0, 466, 466); + SaveEleView_->SetStyle(STYLE_BACKGROUND_OPA, 0); + + + /*初始化label*/ + InitRollLabel(labeltitle, 83, 50, 300, 35, "labletitle", STR_POWER_SAVE_MODE, + DEFAULT_VECTOR_FONT_FILENAME, 30); + // TODO:多国语言 + InitLabelExt(labelnote, 53, 217, 360, 200, "labletitle", STR_SAVENOTE, + DEFAULT_VECTOR_FONT_FILENAME, 30); + labelnote->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + + InitLabelExt(labelkown, 53, labelnote->GetY() + labelnote->GetHeight() + 20, + 360, 100, "labelrecord", STR_SAVEBACK, + DEFAULT_VECTOR_FONT_FILENAME, 30); + labelkown->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + labelkown->SetTextColor(Color::Orange()); + + /*初始化图片*/ + InitImageView(iamgeicon, 188, 121, 80, 90, "saveicon", iconImgPath); + + /*初始化按键*/ + InitButton(buttonno, 110, labelkown->GetY() + labelkown->GetHeight() + 40, + 100, 100, SAVEBUTTONNO); + buttonno->SetImageSrc(butnoImgPath, butnoImgPath); + buttonno->SetOnClickListener(presenter_); + + InitButton(buttonok, 255, labelkown->GetY() + labelkown->GetHeight() + 40, + 100, 100, SAVEBUTTONOK); + buttonok->SetImageSrc(butokImgPath, butokImgPath); + buttonok->SetOnClickListener(presenter_); + + SaveEleView_->Add(labeltitle); + SaveEleView_->Add(labelnote); + SaveEleView_->Add(labelkown); + SaveEleView_->Add(iamgeicon); + SaveEleView_->Add(buttonno); + SaveEleView_->Add(buttonok); + scrollview_->Add(SaveEleView_); + +} + +void SaveEleView::OnStart() { + + View::OnStart(); + + scrollview_ = new UIScrollView(); + if (scrollview_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scrollview_ new fail"); + return; + } + scrollview_->SetScrollBlankSize(35); + scrollview_->SetReboundSize(50); + scrollview_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), + Screen::GetInstance().GetHeight()); + + scrollview_->SetOnDragListener(presenter_); + scrollview_->SetOnRotateListener(presenter_); + scrollview_->SetRotateFactor(2); + scrollview_->RequestFocus(); + scrollview_->SetTouchable(true); + scrollview_->SetDraggable(true); + scrollview_->SetStyle(STYLE_BACKGROUND_COLOR, BACK_GROUND_COLOR); + scrollview_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + + + AddViewToRootContainer(scrollview_); + InitView(); + +} + + +} // namespace OHOS diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepCardView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepCardView.h new file mode 100644 index 000000000..624d48908 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepCardView.h @@ -0,0 +1,37 @@ +/*** + * @Date: 2024-06-25 10:41:32 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-09-03 15:10:21 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepCardView.h + */ +#ifndef SLEEP_CARD_VIEW_H +#define SLEEP_CARD_VIEW_H + +#include "components/root_view.h" +#include "components/ui_card_page.h" +#include "wearable_log.h" +#include "sleep/include/SleepControlView.h" +namespace OHOS +{ + class SleepControlView; + class SleepCardView : public UICardPage + { + public: + SleepCardView(); + virtual ~SleepCardView(); + static SleepCardView *GetInstance(void); + + bool InitView(void); + void PreLoad(void) override; + void UnLoad(void) override; + UISwipeView *GetSleepCardView(); + + private: + void ClearAll(void); + SleepControlView *sleepcontrolView{nullptr}; + UISwipeView *SleepSwipView{nullptr}; + UISwipeView::OnSwipeListener *sleepOnSwipeListener{nullptr}; + bool viewiInitStatus{false}; + }; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepControlPresenter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepControlPresenter.h new file mode 100644 index 000000000..29cfd42be --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepControlPresenter.h @@ -0,0 +1,55 @@ + +/*** + * @Date: 2024-06-25 10:32:53 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-06-25 15:31:40 + * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepControlPresenter.h + */ +#ifndef Sleep_CONTROL_PRESENTER_H +#define Sleep_CONTROL_PRESENTER_H + +#include "Presenter.h" +#include "View.h" +#include "sleep/include/SleepView.h" +#include "sleep/include/SleepModel.h" +#include "sleep/include/SleepControlView.h" +namespace OHOS +{ + class SleepOnSwipeListener : public UISwipeView::OnSwipeListener + { + public: + SleepOnSwipeListener() {} + ~SleepOnSwipeListener() {} + void OnSwipe(UISwipeView &view) override; + }; + + class SleepControlView; + class SleepControlPresenter : public Presenter, + public UIView::OnClickListener, + public RootView::OnKeyActListener, + public UIView::OnDragListener, + public UISwipeView::OnSwipeListener + { + public: + SleepControlPresenter(); + virtual ~SleepControlPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static SleepControlPresenter *GetInstance(); + + private: + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnDragEnd(UIView &view, const DragEvent &event) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; + void OnSwipe(UISwipeView &view) override; + + bool X_DRAG_FLAG{false}; + }; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepControlView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepControlView.h new file mode 100644 index 000000000..4c43d188c --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepControlView.h @@ -0,0 +1,74 @@ +/*** + * @Date: 2024-06-25 10:41:08 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-09-02 09:22:33 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepControlView.h + */ +/*** + * @Date: 2024-06-25 10:41:08 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-06-25 17:26:24 + * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepControlView.h + */ + +#ifndef SleepControl_VIEW_H +#define SleepControl_VIEW_H + +//#include "BaseView.h" +#include "View.h" +#include "components/ui_swipe_view.h" +#include "sleep/include/SleepControlView.h" +#include "sleep/include/SleepTimeView.h" +# include "sleep/include/SleepNapView.h" +#include "sleep/include/SleepControlPresenter.h" + +namespace OHOS +{ + typedef enum + { + MAINSLEEPVIEW = 0, // 主视图 + SLEEPTIMEVIEW, // 详细视图 + SLEEPNAPVIEW, //小睡 + MAX_SLEEPVIEW, + } SleepControlPageId; + +#define SLEEPVIEW "sleepview" + + class SleepControlPresenter; + class SleepControlView : public View + { + + public: + SleepControlView(); + virtual ~SleepControlView(); + static SleepControlView *GetInstance(void); + UISwipeView *SleepControlViewInit(void); + void ClearAll(void); + + AppGroupView *SleepPageInit(void); + AppGroupView *SleepTimePageInit(void); + AppGroupView *SleepNapPageInit(void); + + SleepView *GetSleepView(void); + SleepTimeView *GetSleepTimeView(void); + SleepNapView *GetSleepNapView(void); + + UISwipeView *GetSleepControlPageView(void); + void ChangeView(int16_t hideView, int16_t showView); + + public: + void OnStart() override; + + private: + SleepView *sleepView{nullptr}; + SleepTimeView *sleeptimeView{nullptr}; + SleepNapView *sleepnapView{nullptr}; + + private: + int16_t maxPage = MAX_SLEEPVIEW; + UISwipeView *SleepSwipeViewList{nullptr}; + AppGroupView *recordCard[MAX_SLEEPVIEW]{nullptr}; + AppGroupView *CreatePage(uint8_t SleepControlPageId); + }; +} // namespace OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepModel.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepModel.h new file mode 100644 index 000000000..2a4f8faa5 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepModel.h @@ -0,0 +1,170 @@ + + +#ifndef Sleep_MODEL_H +#define Sleep_MODEL_H + +#include +#include +// #include "AppViewIDs.h" +// #include "UiConfig.h" +// #include "sleep/include/SleepView.h" +// #include "sleep/include/SleepControlPresenter.h" +#include "string" + +#define SLEEP_TIME_PATH "/user/userdata/sleep/%s/sleep_time.bin" +#define SLEEP_STATUS_PATH "/user/userdata/sleep/%s/sleep_status.bin" + +#define NAP_PATH "/user/userdata/sleep/%s/nap.bin" +#define SLEEP_DIR_PATH "/user/userdata/sleep/%s" + +#define SLEEP_DATA_DIR "/user/userdata/sleep/" + +#define SLEEP_STATUS_LENGTH 80 + +namespace OHOS +{ +#pragma pack(push, 1) + typedef struct + { + uint32_t fall_asleep_timestamp; // 入睡 + uint32_t wake_up_timestamp; // 出睡 + uint16_t total_time; // 总时长 + } NAP_T; + + typedef struct + { + uint32_t fall_asleep_timestamp; // 入睡 + uint32_t wake_up_timestamp; // 出睡 + uint16_t total_time; // 总时长 + } SLEEP_T; + + typedef struct + { + uint32_t timestamp; //时间戳 + uint8_t stat; // 状态 + } SLEEP_STAT_T; + +#pragma pack (pop) + + // bool save_nap_data(NAP_T *data); + // uint32_t get_nap_data_size(void); + // bool sleep_mutex_init(void); + uint32_t read_sleep_nap_data(char *data, uint32_t size, FILE *fp); + void set_nap_data(NAP_T *data); + void set_sleep_data(SLEEP_T *data); + // bool save_sleep_data(SLEEP_T *data); + bool read_sleep_data(SLEEP_T *data); + void read_wear_data(void); + bool read_nap_data(NAP_T *data); + // void clean_sleep_data(void); + // bool create_sleep_folder(void); + std::string get_sleep_asleep_time_str(void); + std::string get_sleep_wake_time_str(void); + std::string get_wear_status_str(void); + std::string get_sleep_star_str(void); + //void clean_sleep_file(void); + // 睡眠状态 + enum class SLEEPSTATE + { + WAKE = 0, + SLEEPNOTIFY, + SLEPP, + }; + // 睡眠存储数据 + typedef struct + { + std::string sleeptime; // 睡眠时间 + std::string waketime; // 醒来时间 + uint32_t sleep_timestamp; // 睡眠时间戳 + uint32_t wake_timestamp; // 醒来时间戳 + int totaltime; // 睡眠总时间 + } SleepDataUI; + class SleepModel + { + public: + static SleepModel &GetInstance(void); + void update_time_info(uint32_t timestamp, std::string &timeStr); + void update_sleep(SLEEP_T *data); + void ReInitData(); // 重新刷新UI + void Msg_ReInitData(); + void read_sleep_file_data(); + void msg_save_sleep_data(); + + void set_sleep_goal(); + int get_sleep_hour(); + int get_sleep_min(); + int get_sleep_goal(); + int get_sleep_total(); + + //清除睡眠数据 + void clean_sleep_data(void); + + std::string get_rest_str(); // 解析入睡时间 + std::string get_wake_str(); // 解析醒来时间 + std::string get_goal_str(); // 解析目标休息时间 + std::string get_notifiy(); // 获取提醒时间 + std::string get_sleep_notifiy(); // 获取睡眠时间 + std::string get_wake_notifiy(); // 获取起床时间 + + //小睡数据 + int get_nap_hour(); + int get_nap_min(); + std::string get_napsleep_str(); // 解析入睡时间 + std::string get_napwake_str(); // 解析醒来时间 + + + void set_sleep_state(SLEEPSTATE state); + SLEEPSTATE get_sleep_state(); + SleepDataUI *ReadSleepData(); // 读取睡眠数据 + bool SaveSleepData(const SleepDataUI &data); // 更新睡眠数据 + bool DeleteSleepData(); // 清空睡眠文件 + + bool CheckSleepTime();//对睡眠时间进行校验 + + void UpdateSleepView(); + std::string GetUpdateSleepTime(); + + /*定时器相关*/ + void Sleep_StartTimer(uint32_t interval); + void Sleep_StopTimer(void); + + /*主界面卡片相关*/ + void SetCardId(int cardid) + { + CradId = cardid; + } + int GetCardId() + { + return CradId; + } + + private: + SleepModel(); + SleepModel(const SleepModel &); + SleepModel &operator=(const SleepModel &); + virtual ~SleepModel(); + + std::string sleepStr{"--"}; + std::string wakeStr{"--"}; + std::string goalStr{"--"}; + std::string napsleepStr{"--"}; + std::string napwakeStr{"--"}; + + std::string goalnotifyStr{"--"}; + std::string goalsleepStr{"--"}; + std::string goalwakeStr{"--"}; + + std ::string sleep_time_str{"--"}; + + int sleep_total_time = 0; + int goal_total_time = 0; + int nap_total_time = 0; + + uint32_t sleep_update_time{0}; + + SLEEPSTATE sleepstate_ = SLEEPSTATE::WAKE; + int CradId = 0; // 主界面状态 + }; +} + +#endif // Sleep_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepModelC.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepModelC.h new file mode 100644 index 000000000..9a2874675 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepModelC.h @@ -0,0 +1,31 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2024-10-03 17:09:01 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2024-10-03 18:12:11 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModelC.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ +#ifndef SLEEPMODELC_H +#define SLEEPMODELC_H + +#ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif +#endif + void custom_save_sleep_data(void); + void custom_save_nap_data(void); + void custom_read_sleep_data(void); + void custom_read_nap_data(void); + void custom_sleep_model_updata(void); + void update_sleep_data(uint32_t sleep_timestamp,uint32_t wake_timestamp,uint32_t totaltime); + void update_nap_data(uint32_t sleep_timestamp,uint32_t wake_timestamp,uint32_t totaltime); + void custom_read_wear_data(void); +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif +#endif diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepNapView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepNapView.h new file mode 100644 index 000000000..82d1cdd00 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepNapView.h @@ -0,0 +1,69 @@ +/*** + * @Date: 2024-06-25 14:50:26 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditNap: 2024-07-01 15:10:12 + * @FilePath: + * /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepNapView.h + */ +/*** + * @Date: 2024-06-25 14:50:26 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditNap: 2024-06-25 17:29:03 + * @FilePath: + * /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepNapView.h + */ +/*** + * @Date: 2024-06-25 14:50:26 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditNap: 2024-06-25 16:30:55 + * @FilePath: + * /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepNapView.h + */ + +#ifndef Sleep_Nap_VIEW_H +#define Sleep_Nap_VIEW_H + +//#include "BaseView.h" +#include "View.h" + +#include "components/root_view.h" +#include "components/ui_circle_progress.h" +#include "components/ui_image_animator.h" +#include "components/ui_image_view.h" +#include "components/ui_label_ext.h" +#include "components/ui_scroll_view.h" +#include "components/ui_view_group.h" + +#include "AppGroupView.h" +#include "wearable_log.h" +#include + +namespace OHOS { +class SleepNapView : public AppGroupView { + +public: + SleepNapView(); + virtual ~SleepNapView(); + static SleepNapView *GetInstance(void); + bool InitPage(void); + virtual bool InitView(void *caller) override; + void ClearAll(); + bool GetInitViewState(void); + void SleepDataRefresh(); + +private: + UILabelExt *napsleeptitle{nullptr}; + UILabelExt *napwaketitle{nullptr}; + UILabelExt *naptitle{nullptr}; + UILabelExt *napsleep{nullptr}; + UILabelExt *napwake{nullptr}; + UILabelExt *apptitle{nullptr}; // 详情 + + UIImageView *transverseline_1{nullptr}; // 横线1 + UIImageView *transverseline_2{nullptr}; // 横线2 + UIImageView *verticalline{nullptr}; // 竖线 + bool viewInitStatus{false}; +}; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepTimeView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepTimeView.h new file mode 100644 index 000000000..41404f998 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepTimeView.h @@ -0,0 +1,73 @@ +/*** + * @Date: 2024-06-25 14:50:26 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-07-01 15:10:12 + * @FilePath: + * /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepTimeView.h + */ +/*** + * @Date: 2024-06-25 14:50:26 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-06-25 17:29:03 + * @FilePath: + * /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepTimeView.h + */ +/*** + * @Date: 2024-06-25 14:50:26 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-06-25 16:30:55 + * @FilePath: + * /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepTimeView.h + */ + +#ifndef Sleep_Time_VIEW_H +#define Sleep_Time_VIEW_H + +//#include "BaseView.h" +#include "View.h" + +#include "components/root_view.h" +#include "components/ui_circle_progress.h" +#include "components/ui_image_animator.h" +#include "components/ui_image_view.h" +#include "components/ui_label_ext.h" +#include "components/ui_scroll_view.h" +#include "components/ui_view_group.h" + +#include "AppGroupView.h" +#include "wearable_log.h" +#include + +namespace OHOS { +class SleepTimeView : public AppGroupView { + +public: + SleepTimeView(); + virtual ~SleepTimeView(); + static SleepTimeView *GetInstance(void); + bool InitPage(void); + virtual bool InitView(void *caller) override; + void ClearAll(); + bool GetInitViewState(void); + void SleepDataRefresh(); + +private: + void DumpWeatherInfo(); + +private: + UILabelExt *resttitle{nullptr}; // 作息时间标题 + UILabelExt *sleeptitle{nullptr}; // 入睡时间标题 + UILabelExt *waketitle{nullptr}; // 醒来标题 + UILabelExt *goaltime{nullptr}; // 目标时长 + UILabelExt *goal{nullptr}; // 作息时间 + UILabelExt *sleep{nullptr}; // 入睡时间 + UILabelExt *wake{nullptr}; // 醒来时间 + UIImageView *transverseline_1{nullptr}; // 横线1 + UIImageView *transverseline_2{nullptr}; // 横线2 + UIImageView *verticalline{nullptr}; // 竖线 + UIImageView *upiconimage{nullptr}; + bool viewInitStatus{false}; +}; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepView.h new file mode 100644 index 000000000..b506f3902 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/include/SleepView.h @@ -0,0 +1,60 @@ +/*** + * @Date: 2024-06-25 10:32:22 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-06-25 17:52:16 + * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepView.h + */ + +#ifndef Sleep_VIEW_H +#define Sleep_VIEW_H + +//#include "BaseView.h" +#include "View.h" + +#include "components/root_view.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label_ext.h" +#include "components/ui_image_view.h" +#include "components/ui_image_animator.h" +#include "components/ui_circle_progress.h" + +#include "wearable_log.h" +#include "AppGroupView.h" +#include + +namespace OHOS +{ + class SleepView : public AppGroupView + { + public: + SleepView(); + virtual ~SleepView(); + static SleepView *GetInstance(void); + bool InitPage(void); + virtual bool InitView(void *caller) override; + void ClearAll(); + bool GetInitViewState(void); + void SleepDataRefresh(); // 刷新睡眠数据 + + private: + UICircleProgress *circleProgress_{nullptr}; // 进度条 + + UILabelExt *title{nullptr}; + UILabelExt *hour{nullptr}; + UILabelExt *minute{nullptr}; + + UILabel *time_hour{nullptr}; // 睡眠时间[小时] + UILabel *time_minute{nullptr}; // 睡眠时间[分钟] + + UILabelExt *sleep_update_time{nullptr}; // 目标时间 + + UIImageView *roomimage{nullptr}; + UIImageView *upiconimage{nullptr}; + UIImageView *progress_image = nullptr; + + bool viewInitStatus{false}; + }; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/src/SleepCardView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/src/SleepCardView.cpp new file mode 100644 index 000000000..97ce35cfc --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/src/SleepCardView.cpp @@ -0,0 +1,103 @@ +/*** + * @Date: 2024-06-25 10:41:40 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-06-26 11:27:04 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepCardView.cpp + */ +#include "sleep/include/SleepCardView.h" +#include "sleep/include/SleepControlView.h" +#include "sleep/include/SleepControlPresenter.h" +namespace OHOS +{ + static SleepCardView *g_pSleepCardView = nullptr; + SleepCardView::SleepCardView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SleepCardView::SleepCardView"); + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + g_pSleepCardView = this; + } + SleepCardView::~SleepCardView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SleepCardView::~SleepCardView"); + ClearAll(); + g_pSleepCardView = nullptr; + } + SleepCardView *SleepCardView::GetInstance() + { + return g_pSleepCardView; + } + void SleepCardView::ClearAll(void) + { + if (viewiInitStatus == true) + { + RemoveAll(); + if (sleepcontrolView != nullptr) + { + if (sleepOnSwipeListener != nullptr) + { + delete sleepOnSwipeListener; + sleepOnSwipeListener = nullptr; + } + + if (sleepcontrolView != nullptr) + { + delete sleepcontrolView; + sleepcontrolView = nullptr; + } + if(SleepSwipView) + { + delete SleepSwipView; + SleepSwipView = nullptr; + } + } + } + } + + bool SleepCardView::InitView(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepCardView::InitView"); + sleepcontrolView = new SleepControlView(); + if (sleepcontrolView == nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SleepView::new SleepView fail!"); + return false; + } + + SleepSwipView = dynamic_cast(sleepcontrolView->GetSleepControlPageView()); + if (SleepSwipView == nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SleepView->SleepViewInit() == nullptr!!"); + return false; + } + + sleepOnSwipeListener = static_cast(new SleepOnSwipeListener()); + if (sleepOnSwipeListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleepOnSwipeListener new fail"); + return false; + } + SleepSwipView->SetOnSwipeListener(sleepOnSwipeListener); + Add(SleepSwipView); + + return true; + } + UISwipeView *SleepCardView::GetSleepCardView() + { + return SleepSwipView; + } + void SleepCardView::PreLoad(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepCardView::PreLoad viewiInitStatus %d",viewiInitStatus); + if (!viewiInitStatus) + { + InitView(); + viewiInitStatus = true; + } + } + + void SleepCardView::UnLoad(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepCardView::UnLoad"); + } + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/src/SleepControlPresenter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/src/SleepControlPresenter.cpp new file mode 100644 index 000000000..1dcecc1f3 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/src/SleepControlPresenter.cpp @@ -0,0 +1,121 @@ +/*** + * @Date: 2024-06-25 10:33:08 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-07-12 20:00:41 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepControlPresenter.cpp + */ +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "sleep/include/SleepControlPresenter.h" +#include "common/key_code.h" +#include "common/key_code.h" +#include +#include +#include "UiConfig.h" +#include "string.h" +#include "gfx_utils/mem_check.h" +#include "NativeRegisterManager.h" +#include "uicomponents/UIComponents.h" +namespace OHOS +{ + + REGIST_MENU_PRO(VIEW_SLEEP, SleepControlView, SleepControlPresenter, + PNG_APPLIST_SLEEP_IMAGE_BIG, PNG_APPLIST_SLEEP_IMAGE, PNG_APPLIST_SLEEP_IMAGE, "睡眠", STR_REMOTE_SHOOTING); + + // 当前Presenter属性实例化的内存指针 + static SleepControlPresenter *g_pSleepControlPresenter = nullptr; + + SleepControlPresenter::SleepControlPresenter() + { + // SleepModel = &SleepModel::GetInstance(); + g_pSleepControlPresenter = this; +#ifdef MEM_CHECK + MemCheck::GetInstance()->EnableLeakCheck(true); +#endif + } + + SleepControlPresenter::~SleepControlPresenter() + { + g_pSleepControlPresenter = nullptr; +#ifdef MEM_CHECK + MemCheck::GetInstance()->EnableLeakCheck(false); +#endif + } + + SleepControlPresenter *SleepControlPresenter::GetInstance() + { + + return g_pSleepControlPresenter; + } + + void SleepControlPresenter::OnStart() + { + Presenter::OnStart(); + } + + void SleepControlPresenter::OnPause(void) + { + Presenter::OnPause(); + } + + void SleepControlPresenter::OnResume(void) + { + Presenter::OnResume(); + } + + void SleepControlPresenter::OnStop(void) + { + Presenter::OnStop(); + } + + bool SleepControlPresenter::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 + { + SleepControlPresenter::X_DRAG_FLAG = true; + } + return true; + } + + bool SleepControlPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " SleepControlPresenter::OnDragEnd"); + UNUSED(view); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && SleepControlPresenter::X_DRAG_FLAG) + { + NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); + } + return true; + } + + bool SleepControlPresenter::OnClick(UIView &view, const ClickEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " SleepControlPresenter::OnClick"); + + UNUSED(view); + UNUSED(event); + return true; + } + + // 增加按键事件 + bool SleepControlPresenter::OnKeyAct(UIView &view, const KeyEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + uint16_t keyState = event.GetState(); + // 如果是power键就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); + } + return true; + } + + void SleepControlPresenter::OnSwipe(UISwipeView &view) {} + void SleepOnSwipeListener::OnSwipe(UISwipeView &view) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepOnSwipeListener::OnSwipe,current tab index = %d", view.GetCurrentPage()); + return; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/src/SleepControlView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/src/SleepControlView.cpp new file mode 100644 index 000000000..dd1492e04 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/src/SleepControlView.cpp @@ -0,0 +1,217 @@ +/*** + * @Date: 2024-09-02 14:46:10 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-09-03 16:01:25 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepControlView.cpp + */ +/*** + * @Date: 2024-06-25 10:41:15 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-06-25 14:54:49 + * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepControlControlView.cpp + */ + +#include "sleep/include/SleepControlView.h" +#include "sleep/include/SleepControlPresenter.h" +#include "sleep/include/SleepModel.h" +#include "wearable_log.h" +namespace OHOS +{ + static SleepControlView *g_pSleepControlView{nullptr}; + SleepControlView::SleepControlView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SleepControlView::SleepControlView"); + g_pSleepControlView = this; + } + + SleepControlView::~SleepControlView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SleepControlView::~SleepControlView"); + ClearAll(); + g_pSleepControlView = nullptr; + } + + SleepControlView *SleepControlView::GetInstance(void) + { + return g_pSleepControlView; + } + + void SleepControlView::ClearAll(void) + { + if (SleepSwipeViewList != nullptr) + { + for (int32_t i = 0; i < maxPage; i++) + { + recordCard[i] = nullptr; + } + + SleepSwipeViewList->RemoveAll(); + + delete sleepView; + sleepView = nullptr; + + delete sleeptimeView; + sleeptimeView = nullptr; + + delete sleepnapView; + sleepnapView = nullptr; + + delete SleepSwipeViewList; + SleepSwipeViewList = nullptr; + } + } + /*初始化主睡眠界面VIEW*/ + UISwipeView *SleepControlView::SleepControlViewInit(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepControlView::SleepControlViewInit"); + SleepSwipeViewList = new UISwipeView(UISwipeView::VERTICAL); + if (nullptr == SleepSwipeViewList) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepSwipeViewList new fail!!"); + return nullptr; + } + + SleepSwipeViewList->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + SleepSwipeViewList->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + // SleepSwipeViewList->SetAnimatorTime(50); + SleepSwipeViewList->SetDraggable(true); + SleepSwipeViewList->SetTouchable(true); + for (uint16_t i = 0; i < maxPage; i++) + { + recordCard[i] = CreatePage(i); + if (nullptr == recordCard[i]) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "recordCard[%d] is nullptr!!", i); + return nullptr; + } + recordCard[i]->InitView(this); + SleepSwipeViewList->Add(recordCard[i]); + } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepControlView InitPage over!!"); + return SleepSwipeViewList; + } + + /*获取睡眠主界面*/ + UISwipeView *SleepControlView::GetSleepControlPageView() + { + return SleepControlViewInit(); + } + + /*OnStart 增加界面控制*/ + void SleepControlView::OnStart() + { + View::OnStart(); + AddViewToRootContainer(new UIViewGroup()); + GetRootContainer()->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + GetRootContainer()->SetTouchable(true); + GetRootContainer()->SetDraggable(true); + AddViewToRootContainer(GetSleepControlPageView()); + // RootView::GetInstance()->Add(GetSleepControlPageView()); + + if (SleepSwipeViewList == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepSwipeViewList is nullptr!"); + return; + } + + auto sleepPresenter = dynamic_cast(OHOS::SleepControlPresenter::GetInstance()); + if (sleepPresenter == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get SleepControlPresenter instance"); + return; + } + + SleepSwipeViewList->SetOnClickListener(sleepPresenter); + SleepSwipeViewList->SetOnDragListener(sleepPresenter); + SleepSwipeViewList->SetOnSwipeListener(sleepPresenter); + + RootView::OnKeyActListener *keyactListener = dynamic_cast(sleepPresenter); + if (keyactListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to set key act listener"); + return; + } + + RootView::GetInstance()->SetOnKeyActListener(keyactListener); + } + + + SleepView *SleepControlView::GetSleepView(void) + { + return sleepView; + } + + SleepTimeView *SleepControlView::GetSleepTimeView(void) + { + return sleeptimeView; + } + SleepNapView *SleepControlView::GetSleepNapView(void) + { + return sleepnapView; + } + AppGroupView *SleepControlView::SleepPageInit(void) + { + sleepView = new SleepView(); + if (sleepView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleepView::new SleepView fail!"); + return nullptr; + } + + return sleepView; + } + + AppGroupView *SleepControlView::SleepTimePageInit(void) + { + sleeptimeView = new SleepTimeView(); + if (sleeptimeView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleeptimeView::new SleepTimeView fail!"); + return nullptr; + } + + return sleeptimeView; + } + AppGroupView *SleepControlView::SleepNapPageInit(void) + { + sleepnapView = new SleepNapView(); + if (sleepnapView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleepnapView::new SleepNapView fail!"); + return nullptr; + } + + return sleepnapView; + } + + struct SleepControlViewMapper + { + const int16_t viewId; + AppGroupView *(SleepControlView::*func)(void); + }; + + static const SleepControlViewMapper g_pageMapper[] = { + {MAINSLEEPVIEW, &SleepControlView::SleepPageInit}, + {SLEEPTIMEVIEW, &SleepControlView::SleepTimePageInit}, + {SLEEPNAPVIEW, &SleepControlView::SleepNapPageInit}, + }; + + AppGroupView *SleepControlView::CreatePage(uint8_t SleepControlPageId) + { + uint16_t i; + AppGroupView *view = nullptr; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CreatePage SleepControlPageId:%d", SleepControlPageId); + + for (i = 0; i < sizeof(g_pageMapper) / sizeof(g_pageMapper[0]); i++) + { + if (g_pageMapper[i].viewId == SleepControlPageId) + { // 正确使用 SleepControlPageId 来匹配视图ID + view = (this->*(g_pageMapper[i].func))(); // 如果找到匹配项,则调用相应的函数创建视图 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CreatePage view:%p", view); + return view; // 返回创建的视图 + } + } + return nullptr; // 如果没有找到匹配的视图ID,返回 nullptr + } + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/src/SleepModel.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/src/SleepModel.cpp new file mode 100644 index 000000000..b4024fd01 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/src/SleepModel.cpp @@ -0,0 +1,1019 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: SLEPPNOTIFY24-06-26 19:36:48 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2024-11-27 11:15:14 + * @FilePath: + * /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp + * @Description: + * + * Copyright (c) SLEPPNOTIFY24 by ${git_name_email}, All Rights Reserved. + */ + +#include "sleep/include/SleepModel.h" +#include "ConfigModel.h" +#include "UiConfig.h" +#include "custom_utils.h" +#include "heart_blood/health_service/health_service.h" +#include "kv_store.h" +#include "samgr_lite.h" +#include "securec.h" +#include "sleep/include/SleepControlPresenter.h" +#include "ui_resource_image.h" +#include "wearable_log.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ConfigModelC.h" +#include "MainModel.h" +#include "broadcast_feature.h" +#include "broadcast_service.h" +#include "cmsis_os.h" +#include "custom_runtime.h" +//#include "cywee_service.h" +#include "power_display_service.h" +#include "sleep/include/SleepModelC.h" +#include "thread_adapter.h" +#include "ui_service.h" +#include +#include + +extern "C" errcode_t uapi_get_TIME_STR(uint32_t time, char *p_time, + char date_separator, char time_separator, + date_format_t format); +extern "C" int get_sleep_time_from_config_model(void); +extern "C" int get_wake_up_time_from_config_model(); + + +static uint32_t len = 0; +static OHOS::SLEEP_STAT_T *wear_stat; +namespace OHOS +{ +#define SLEPPNOTIFY 20 + + static NAP_T nap_data = {0}; + static SLEEP_T sleep_data = {0}; + + static uint32_t sleep_update_timestamp = 0; + static uint32_t nap_update_timestamp = 0; + + void SleepModel::clean_sleep_data(void) + { + sleep_update_timestamp = 0; + nap_update_timestamp = 0; + memset(&sleep_data,0,sizeof(SLEEP_T)); + memset(&nap_data, 0, sizeof(NAP_T)); + } + + /*获取最新睡眠时间戳*/ + uint32_t get_sleep_update_timestamp(void) + { + if (nap_update_timestamp <= sleep_update_timestamp) + return sleep_update_timestamp; + else + return nap_update_timestamp; + } + + static char nap_file_path[64] = {0}; + + + bool is_regular_file(const std::string &file_name) + { + struct stat file_stat; + if (stat(file_name.c_str(), &file_stat) != 0) + { + return false; + } + + return S_ISREG(file_stat.st_mode); // 检查文件是否为普通文件 + } + + std::string get_wear_status_str(void) + { + std::string result; + std::string wear_status; + // 进行文件读取 + do_custom_fileoperate_service_check_msg( + CUSTOM_FILEOPERATE_MSG_TYPE_WEAR_DATA_READ, nullptr, 0); + LOS_Msleep(100); // 等待文件系统准备 + + if(len == 0) + return result; + + for(int i = 0; i < len/5; i++) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"data.timestamp : %d , data.stat : %d", wear_stat[i].timestamp,wear_stat[i].stat); + if(wear_stat[i].stat) + wear_status = "已配戴"; + else + wear_status = "未配戴"; + + std::string timestr; + char labelTime[20] = {0}; + + if (uapi_get_TIME_STR(wear_stat[i].timestamp, labelTime, '.', ':', DATE_Y_M_D_H_M) != ERRCODE_SUCC) + { + timestr = "--"; + } + else + { + timestr = labelTime; + } + + result += wear_status + ":"+ timestr + "\n"; + } + free(wear_stat); + return result; // 返回结果字符串 + } + + std::string get_sleep_star_str(void) + { + + std::string result; + + uint16_t datelen = 0; + uint8_t sleep_data[256] = {0}; + + uint32_t asleep_time = 0; + uint32_t wake_up_time = 0; + uint16_t total_time = 0; + uint16_t total_deep_sleep_time = 0; + uint16_t total_mild_sleep_time = 0; + uint16_t total_rem_sleep_time = 0; + uint16_t total_wake_time = 0; + uint32_t timestampe = 0; + int status = -1; + uint8_t index = 0; + char timestampe_str[10] = {0}; + char status_str[20] = {0}; + + char day[12] = {0}; + uapi_get_YYMMDD_Time(day, '\0'); + + char file_path[64] = {0}; + sprintf_s(file_path, 64, SLEEP_TIME_PATH, day); + + uapi_get_file_data(file_path,sleep_data,&datelen); + + if(datelen == 0) + { + PRINT("fread error datelen == 0 \n"); + return "没有文件"; + } + + asleep_time = *(uint32_t*)&sleep_data[1]; + wake_up_time = *(uint32_t*)&sleep_data[5]; + + total_time = sleep_data[9] * 60 + sleep_data[10]; + total_deep_sleep_time = sleep_data[11] * 60 + sleep_data[12]; + total_mild_sleep_time = sleep_data[13] * 60 + sleep_data[14]; + total_rem_sleep_time = sleep_data[15] * 60 + sleep_data[16]; + total_wake_time = sleep_data[17] * 60 + sleep_data[18]; + + char asleep_time_str[10] = {0}; + uapi_get_TIME_STR(asleep_time,asleep_time_str, '.', ':',DATE_H_M); + + char wake_up_time_str[10] = {0}; + uapi_get_TIME_STR(wake_up_time,wake_up_time_str, '.', ':',DATE_H_M); + + + result += std::string("入睡时间: ") + asleep_time_str + " " + std::to_string(asleep_time) + "\n"; + result += std::string("出睡时间: ") + wake_up_time_str + " " + std::to_string(wake_up_time) + "\n"; + result += std::string("总时长: ") + std::to_string(total_time) + "\n"; + result += std::string("深睡时长: ") + std::to_string(total_deep_sleep_time) + "\n"; + result += std::string("浅睡时长: ") + std::to_string(total_mild_sleep_time) + "\n"; + result += std::string("快速眼动时长: ") + std::to_string(total_rem_sleep_time) + "\n"; + result += std::string("清醒时长: ") + std::to_string(total_wake_time) + "\n"; + + // PRINT("入睡时间 : %s %d \n",asleep_time_str,asleep_time); + // PRINT("出睡时间 : %s %d \n",wake_up_time_str,wake_up_time); + // PRINT("总时长 : %d 分钟\n",total_time); + // PRINT("深睡时长 : %d 分钟\n",total_deep_sleep_time); + // PRINT("浅睡时长 : %d 分钟\n",total_mild_sleep_time); + // PRINT("快速眼动时长 : %d 分钟\n",total_rem_sleep_time); + // PRINT("清醒时长 : %d 分钟\n",total_wake_time); + + char statuspath[64] = {0}; + uapi_get_YYMMDD_Time(day, '\0'); + sprintf_s(statuspath, 64, SLEEP_STATUS_PATH, day); + + + memset(sleep_data,0,sizeof(sleep_data)); + datelen = 0; + uapi_get_file_data(statuspath,sleep_data,&datelen); + + if(datelen == 0) + { + PRINT("fread error datelen == 0 \n"); + return result += "\n 没有状态文件"; + } + + while(datelen) + { + memset(timestampe_str,0,sizeof(timestampe_str)); + memset(status_str,0,sizeof(status_str)); + timestampe = *(uint32_t*)&sleep_data[index]; + uapi_get_TIME_STR(timestampe,timestampe_str, '.', ':',DATE_H_M); + status = sleep_data[index + 4]; + //0进入睡眠 1潜睡 2深睡 3清醒 4结束睡眠 6入睡 7出睡最后一笔输出 8未出睡最后一笔输出 12快速动眼 13取消入睡 + switch(status) + { + case 0: + strcpy(status_str,"进入睡眠"); + break; + case 1: + strcpy(status_str,"浅睡"); + break; + case 2: + strcpy(status_str,"深睡"); + break; + case 3: + strcpy(status_str,"清醒"); + break; + case 4: + strcpy(status_str,"结束睡眠"); + break; + case 6: + strcpy(status_str,"入睡通知"); + break; + case 7: + strcpy(status_str,"出睡最后一笔输出"); + break; + case 9: + strcpy(status_str,"未出睡最后一笔输出"); + break; + case 12: + strcpy(status_str,"快速动眼"); + break; + case 13: + strcpy(status_str,"取消入睡"); + break; + default: + break; + + } + + // PRINT("时间 : %d %s 状态:%s\n",timestampe,timestampe_str,status_str); + + result += std::string(status_str) + std::to_string(timestampe) + "\n"; + + index+=5; + datelen -= 5; + } + return result; + } + + std::string get_sleep_asleep_time_str(void) + { + std::string timestr; + char labelTime[20] = {0}; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleep_data.fall_asleep_timestamp : %d",sleep_data.fall_asleep_timestamp); + if (uapi_get_TIME_STR(sleep_data.fall_asleep_timestamp, labelTime, '.', ':', DATE_Y_M_D_H_M) != ERRCODE_SUCC || !sleep_data.fall_asleep_timestamp) + { + timestr = "--"; + } + else + { + timestr = labelTime; + } + return timestr; + } + + std::string get_sleep_wake_time_str(void) + { + std::string timestr; + char labelTime[20] = {0}; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleep_data.wake_up_timestamp : %d",sleep_data.wake_up_timestamp); + if (uapi_get_TIME_STR(sleep_data.wake_up_timestamp, labelTime, '.', ':', DATE_Y_M_D_H_M) != ERRCODE_SUCC || !sleep_data.wake_up_timestamp) + { + timestr = "--"; + } + else + { + timestr = labelTime; + } + return timestr; + } + + void read_wear_data(void) + { + uint32_t size = 0; + len = uapi_get_file_size("user/userdata/wear.bin"); + if(!len) + return; + + wear_stat = (SLEEP_STAT_T *)malloc(len); + FILE *fp; + + fp = fopen("user/userdata/wear.bin", "rb"); + if (fp == NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "wear file open failed"); + free(wear_stat); + return; + } + + size = fread(wear_stat, 1, len, fp); + if(size != len) + { + free(wear_stat); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "wear file read failed"); + } + fclose(fp); + } + + bool read_sleep_data(SLEEP_T *data) + { + char day[12] = {0}; + uapi_get_YYMMDD_Time(day, '\0'); + + char file_path[64] = {0}; + sprintf_s(file_path, 64, SLEEP_TIME_PATH, day); + + FILE *fp = fopen(file_path, "rb"); + if (fp == NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "read_sleep_data fopen fail %s \n",file_path); + // osal_mutex_unlock(&sleep_mutex); + return false; + } + + // 读取睡眠类型 + uint8_t sleep_type; + fread(&sleep_type, 1, 1, fp); + + if (sleep_type == 0) + { + fclose(fp); + // osal_mutex_unlock(&sleep_mutex); + return false; + } + + // 入睡时间 + uint32_t fall_asleep_timestamp; + fread(&fall_asleep_timestamp, 1, 4, fp); + + // 起床时间 + uint32_t wake_up_timestamp; + fread(&wake_up_timestamp, 1, 4, fp); + + // 睡眠总时间 + uint8_t total_time_hour, total_time_minute; + fread(&total_time_hour, 1, 1, fp); + fread(&total_time_minute, 1, 1, fp); + uint16_t total_time = total_time_hour * 60 + total_time_minute; + + // 累加睡眠数据 + data->fall_asleep_timestamp = fall_asleep_timestamp; + data->wake_up_timestamp = wake_up_timestamp; + data->total_time = total_time; + + sleep_update_timestamp = wake_up_timestamp; + + fclose(fp); + + // osal_mutex_unlock(&sleep_mutex); + + return true; + } + + bool read_nap_data(NAP_T *data) + { + char day[12] = {0}; + uapi_get_YYMMDD_Time(day, '\0'); + + sprintf_s(nap_file_path, 64, NAP_PATH, day); + + FILE *fp = fopen(nap_file_path, "rb"); + if (fp == NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "read_nap_data %s fopen fail", nap_file_path); + return false; + } + + if(uapi_get_file_size(nap_file_path) > 14) //存在多段小睡 UI显示最新的一次数据 + fseek(fp, -14, SEEK_END);//移到最后一段数据 + + fseek(fp, 3, SEEK_CUR); // 将文件指针移动到睡眠类型 + + //读取睡眠类型 + uint8_t sleep_type; + fread(&sleep_type, 1, 1, fp); + + if (sleep_type == 1) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleep_type error!!!"); + fclose(fp); + return false; + } + // 入睡时间 + uint32_t fall_asleep_timestamp; + fread(&fall_asleep_timestamp, 1, 4, fp); + + // 起床时间 + uint32_t wake_up_timestamp; + fread(&wake_up_timestamp, 1, 4, fp); + + // 睡眠总时间 + uint8_t total_time_hour, total_time_minute; + fread(&total_time_hour, 1, 1, fp); + fread(&total_time_minute, 1, 1, fp); + uint16_t total_time = total_time_hour * 60 + total_time_minute; + + // 累加睡眠数据 + data->fall_asleep_timestamp = fall_asleep_timestamp; + data->wake_up_timestamp = wake_up_timestamp; + data->total_time = total_time; + + nap_update_timestamp = wake_up_timestamp; + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "fall_asleep_timestamp : %d wake_up_timestamp : %d total_time : %d ", data->fall_asleep_timestamp, data->wake_up_timestamp, data->total_time); + + fclose(fp); + + return true; + } + void set_sleep_data(SLEEP_T *data) + { + memset(&sleep_data, 0, sizeof(SLEEP_T)); + memcpy_s(&sleep_data, sizeof(SLEEP_T), data, sizeof(SLEEP_T)); + // 刷新model里面的数据 + // SleepModel::GetInstance().update_sleep(&sleep_data); + } + /* -------------------------------------------------------------------------- */ + SleepModel::SleepModel() + { + // 初始化配置睡眠目标 + set_sleep_goal(); + // 刷新数据 + Msg_ReInitData(); + } + SleepModel::~SleepModel() {} + SleepModel &SleepModel::GetInstance() + { + static SleepModel instance; + return instance; + } + void SleepModel::Msg_ReInitData() { + do_custom_fileoperate_service_check_msg( + CUSTOM_FILEOPERATE_MSG_TYPE_SLEEPMODLE_UPDATE, nullptr, 0); + } + + + //更新睡眠model数据 + void SleepModel::ReInitData() + { + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "ReadSleepData sleepStr %u wakeStr %u sleep_total_time %d", + sleep_data.fall_asleep_timestamp, + sleep_data.wake_up_timestamp, sleep_data.total_time); + if (sleep_data.fall_asleep_timestamp) + { + update_time_info(sleep_data.fall_asleep_timestamp, sleepStr); + update_time_info(sleep_data.wake_up_timestamp, wakeStr); + } + else + { + sleepStr = "--"; + wakeStr = "--"; + } + sleep_total_time = sleep_data.total_time; + } + { + if (nap_data.fall_asleep_timestamp) + { + update_time_info(nap_data.fall_asleep_timestamp, napsleepStr); + update_time_info(nap_data.wake_up_timestamp, napwakeStr); + } + else + { + napsleepStr = "--"; + napwakeStr = "--"; + } + nap_total_time = nap_data.total_time; + } + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "ReadSleepData sleepStr %s wakeStr %s sleep_total_time %d nap_total_time %d napsleepStr %s napwakeStr %s", + sleepStr.c_str(), wakeStr.c_str(), sleep_total_time, nap_total_time, napsleepStr.c_str(), napwakeStr.c_str()); + + // delete data; // 释放内存 + } + + // 开机读取 + void SleepModel::read_sleep_file_data() { + custom_read_sleep_data(); + custom_read_nap_data(); + + } + // 保存睡眠数据 + void SleepModel::msg_save_sleep_data() { + // 配置睡眠数据 + int cmd = 0; + // do_cywee_service_check_msg(CYWEE_SERVICE_CMD_GET_SLEEP_DATA,&cmd); // 获取睡眠数据 但不中止睡眠 + } + + void SleepModel::UpdateSleepView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "睡眠数据更新"); + SleepControlView *p_SleepControlView = SleepControlView::GetInstance(); + if (p_SleepControlView != nullptr) + { + if (p_SleepControlView->GetSleepView()) + { + p_SleepControlView->GetSleepView()->SleepDataRefresh(); + } + if (p_SleepControlView->GetSleepTimeView()) + { + p_SleepControlView->GetSleepTimeView()->SleepDataRefresh(); + } + if (p_SleepControlView->GetSleepNapView()) + { + p_SleepControlView->GetSleepNapView()->SleepDataRefresh(); + } + } + } + static constexpr const char *SLEEP_JSON_PATH = + "/user/userdata/health/sleep.json"; + // 读取睡眠数据 + SleepDataUI *SleepModel::ReadSleepData() + { + + // 判断文件夹是否存在 + if (!HealthService::GetInstance()->CreateHealthFolder()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateHealthFolder file"); + return nullptr; + } + + // 读取文件 + std::ifstream inFile(SLEEP_JSON_PATH); + if (!inFile.is_open()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to open JSON file"); + return nullptr; + } + + // 读取文件内容到字符串 + std::stringstream buffer; + buffer << inFile.rdbuf(); + std::string jsonDataString = buffer.str(); + const char *jsonData = jsonDataString.c_str(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "jsonData: %s", jsonData); + + // 关闭文件 + inFile.close(); + if (jsonDataString.empty()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "jsonDataString is empty"); + return nullptr; + } + + cJSON *sleep_root = cJSON_Parse(jsonData); + if (sleep_root == NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleep_root is empty"); + return nullptr; + } + + SleepDataUI *data = new SleepDataUI(); + + cJSON *sleeptime_item = cJSON_GetObjectItem(sleep_root, "sleeptime"); + cJSON *waketime_item = cJSON_GetObjectItem(sleep_root, "waketime"); + cJSON *totaltime_item = cJSON_GetObjectItem(sleep_root, "totaltime"); + cJSON *sleep_timestamp_item = + cJSON_GetObjectItem(sleep_root, "sleep_timestamp"); + cJSON *wake_timestamp_item = + cJSON_GetObjectItem(sleep_root, "wake_timestamp"); + + if (sleeptime_item && waketime_item && totaltime_item) + { + data->sleeptime = sleeptime_item->valuestring; + data->waketime = waketime_item->valuestring; + data->totaltime = totaltime_item->valueint; + // 增加时间戳 + data->sleep_timestamp = sleep_timestamp_item->valueint; + data->wake_timestamp = wake_timestamp_item->valueint; + } + else + { + // 读取的数据异常 + cJSON_Delete(sleep_root); + delete data; + return nullptr; + } + + cJSON_Delete(sleep_root); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ReadSleepData is ok!"); + + // 返回结构体 + return data; + } + + // 更新睡眠数据 + bool SleepModel::SaveSleepData(const SleepDataUI &data) + { + // 判断文件夹是否存在 + if (!HealthService::GetInstance()->CreateHealthFolder()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateHealthFolder file"); + return false; + } + + // 覆盖存储 + std::ofstream outFile(SLEEP_JSON_PATH, std::ios::trunc); + if (!outFile.is_open()) + { + // 文件创建失败 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "Failed to create or open JSON file for writing"); + return false; + } + + // 创建一个 JSON 对象 + cJSON *sleep_root = cJSON_CreateObject(); + if (sleep_root == NULL) + { + outFile.close(); + return false; + } + + cJSON_AddItemToObject(sleep_root, "sleeptime", + cJSON_CreateString(data.sleeptime.c_str())); + cJSON_AddItemToObject(sleep_root, "waketime", + cJSON_CreateString(data.waketime.c_str())); + cJSON_AddItemToObject(sleep_root, "totaltime", + cJSON_CreateNumber(data.totaltime)); + cJSON_AddItemToObject(sleep_root, "sleep_timestamp", + cJSON_CreateNumber(data.sleep_timestamp)); + cJSON_AddItemToObject(sleep_root, "wake_timestamp", + cJSON_CreateNumber(data.wake_timestamp)); + + char *jsonData = cJSON_Print(sleep_root); + if (jsonData == NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to generate JSON data"); + cJSON_free(sleep_root); + outFile.close(); + return false; + } + + // 写入 JSON 数据到文件 + outFile << jsonData; + + cJSON_free(sleep_root); + free(jsonData); + outFile.close(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UpdateHealthData JSON is ok"); + + return true; + } + std::string SleepModel::GetUpdateSleepTime() + { + sleep_time_str.clear(); + // 获取睡眠最新时间 + sleep_update_time = get_sleep_update_timestamp(); + // 获取时间戳 + update_time_info(sleep_update_time, sleep_time_str); + return sleep_time_str; + } + //校验时间更新 + bool SleepModel::CheckSleepTime() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CheckSleepTime %d",sleep_update_time); + // 获取睡眠最新时间 + if (sleep_update_time != 0) { + return true; + } + return false; + } + void SleepModel::update_sleep(SLEEP_T *data) + { + if (data == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Invalid input data"); + return; + } + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "fall_asleep_timestamp:%d wake_up_timestamp:%d total_time:%d", + data->fall_asleep_timestamp, data->wake_up_timestamp, + data->total_time); + + SleepDataUI *UIdata = ReadSleepData(); + if (UIdata != nullptr) + { + // 入睡时间是最早时间 + if (data->fall_asleep_timestamp < UIdata->sleep_timestamp || + UIdata->sleep_timestamp == 0) + { + UIdata->sleep_timestamp = data->fall_asleep_timestamp; + } + // 起床时间是最晚时间 + if (data->wake_up_timestamp > UIdata->wake_timestamp || + UIdata->wake_timestamp == 0) + { + UIdata->wake_timestamp = data->wake_up_timestamp; + } + // 总时间需要累加 + UIdata->totaltime += data->total_time; + + update_time_info(UIdata->sleep_timestamp, sleepStr); + update_time_info(UIdata->wake_timestamp, wakeStr); + UIdata->sleeptime = sleepStr; + UIdata->waketime = wakeStr; + + sleep_total_time = UIdata->totaltime; + + SaveSleepData(*UIdata); + } + delete UIdata; // Free memory if dynamically allocated + } + + // 清空睡眠数据 + bool SleepModel::DeleteSleepData() + { + // ReInitData(); // 刷新 + do_custom_fileoperate_service_check_msg(CUSTOM_FILEOPERATE_MSG_TYPE_SLEEPMODLE_UPDATE, nullptr, 0); + return true; + } + + // 时间戳->字符串 + void SleepModel::update_time_info(uint32_t timestamp, std::string &timeStr) + { + // 如果时间戳为0,设置时间字符串为默认值 + if (timestamp == 0) + { + timeStr = "--"; + return; + } + // 解析时间戳 + char labelTime[20]; + if (uapi_get_TIME_STR(timestamp, labelTime, '.', ':', DATE_H_M) == + ERRCODE_SUCC) + { + timeStr.assign(labelTime); + } + else + { + timeStr = "--"; // 如果获取失败,设置为默认值 + } + } + + /* + 设置睡眠目标 + 前2个字节是显示睡眠小时 + 后2个字节显示睡眠分钟 + 需要单独解析出来。 + */ + void SleepModel::set_sleep_goal() + { + // 将原3个字符串清空 + goalnotifyStr.clear(); + goalsleepStr.clear(); + goalwakeStr.clear(); + + int goal_sleep = get_sleep_time_from_config_model(); + int goal_wake = get_wake_up_time_from_config_model(); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "goal_sleep:%d goal_wake:%d", + goal_sleep, goal_wake); + /* -------------------------------------------------------------------------- + */ + // 提取小时部分(前2字节) + int goal_sleep_hour = goal_sleep >> 16; + // 提取分钟部分(后2字节) + int goal_sleep_min = goal_sleep & 0x00FF; + std::ostringstream sleeposs; + sleeposs << std::setfill('0') << std::setw(2) << goal_sleep_hour << ":" + << std::setw(2) << goal_sleep_min; + // 睡眠时间点字符串 + goalsleepStr = sleeposs.str(); + + /* -------------------------------------------------------------------------- + */ + // 需要配置提醒字符串 减去SLEPPNOTIFY分钟的计算 + int notify_min = + (goal_sleep_min >= SLEPPNOTIFY) + ? goal_sleep_min - SLEPPNOTIFY + : ((goal_sleep_min + 60) - SLEPPNOTIFY); // 避免分钟数为负 + int notify_hour = goal_sleep_hour; + if (goal_sleep_min < SLEPPNOTIFY) + { // 如果需要借位 + notify_hour -= 1; // 小时减1 + } + // 确保小时数正确 + notify_hour = + (notify_hour < 0) + ? 23 + : notify_hour; // 处理从0点前SLEPPNOTIFY分钟的情况,变为前一天的23点40分 + // 格式化提醒时间字符串 + std::ostringstream notifyoss; + notifyoss << std::setfill('0') << std::setw(2) << notify_hour << ":" + << std::setw(2) << notify_min; + // 设置提醒字符串 + goalnotifyStr = notifyoss.str(); + /* -------------------------------------------------------------------------- + */ + + int goal_wake_hour = goal_wake >> 16; + int goal_wake_min = goal_wake & 0x00FF; + std::ostringstream wakeoss; + wakeoss << std::setfill('0') << std::setw(2) << goal_wake_hour << ":" + << std::setw(2) << goal_wake_min; + // 起床时间点字符串 + goalwakeStr = wakeoss.str(); + /* -------------------------------------------------------------------------- + */ + + // 睡眠字符串 以及总时长 + goalStr = goalsleepStr + "-" + goalwakeStr; + // goal_total_time 计算 + int total_hours; + if (goal_wake_hour < goal_sleep_hour) + { + total_hours = (goal_wake_hour + 24) - goal_sleep_hour; // 跨天情况 + } + else + { + total_hours = goal_wake_hour - goal_sleep_hour; + } + + int total_minutes = goal_wake_min - goal_sleep_min; + if (total_minutes < 0) + { + total_hours--; // 如果分钟差为负数,小时差减1 + total_minutes += 60; // 转换为正数,加60分钟 + } + goal_total_time = total_hours; // 确保最小时间为0小时 + + /*通知界面更新*/ + // SendMsgToUIService(UI_UPDATE_SLEEP_DATA, 0, nullptr, 0); + } + // 获取睡眠总时长(小时) + int SleepModel::get_sleep_hour() { return sleep_total_time / 60; } + // 获取睡眠总时长(分钟) + int SleepModel::get_sleep_min() { return sleep_total_time % 60; } + // 获取睡眠总时长(目标) + int SleepModel::get_sleep_goal() { return goal_total_time; } + // 获取睡眠总时长(实际) + int SleepModel::get_sleep_total() { return sleep_total_time; } + // 获取实际入睡时间str + std::string SleepModel::get_rest_str() { return sleepStr; } + // 获取实际醒来时间str + std::string SleepModel::get_wake_str() { return wakeStr; } + // 获取目标休息时间str + std::string SleepModel::get_goal_str() { return goalStr; } + // 获取 目标睡眠提醒 时间点str + std::string SleepModel::get_notifiy() { return goalnotifyStr; } + // 获取 目标睡眠 时间点str + std::string SleepModel::get_sleep_notifiy() { return goalsleepStr; } + + // 获取 目标起床 时间点str + std::string SleepModel::get_wake_notifiy() { return goalwakeStr; } + // 设置睡眠状态 + void SleepModel::set_sleep_state(SLEEPSTATE state) { sleepstate_ = state; } + // 获取睡眠状态 + SLEEPSTATE SleepModel::get_sleep_state() { return sleepstate_; } + // 小睡数据 + int SleepModel::get_nap_hour() { return nap_total_time / 60; } + int SleepModel::get_nap_min() { return nap_total_time % 60; } + // 小睡数据字符串 + std::string SleepModel::get_napsleep_str() { return napsleepStr; } + std::string SleepModel::get_napwake_str() { return napwakeStr; } + /* ---------------------------------- 睡眠定时器 + * --------------------------------- */ + + // 声明定时器变量 + static osTimerId_t g_timer = NULL; + + /*定时器到期时的处理*/ + static void Sleep_TimerCallbackProc(int data) + { + // 发起新闹钟 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Sleep_TimerCallbackProc"); + SleepModel::GetInstance().Sleep_StopTimer(); // 关闭定时器 + CustomEventPublish(TOPIC_EVENT_SLEEPNOTE, NULL, 0); // 发送睡眠弹窗 + } + + static void Sleep_TimerCallback(int data) + { + GraphicService::GetInstance()->PostGraphicEvent( + std::bind(Sleep_TimerCallbackProc, data)); + } + + void SleepModel::Sleep_StartTimer(uint32_t interval) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepModel::Sleep_StartTimer"); + if (g_timer != NULL) + { + WEARABLE_LOGE( + WEARABLE_LOG_MODULE_APP, + "CountDownModel::CountDown_StartTimer Timer already exists!!"); + return; + } + g_timer = + osTimerNew((osTimerFunc_t)Sleep_TimerCallback, osTimerOnce, NULL, NULL); + if (g_timer == NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "CountDownModel::CountDown_StartTimer Timer create failed!!"); + return; + } + int tick = osMs2Tick(interval); + osStatus_t ret = osTimerStart(g_timer, tick); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "[CountDown_StartTimer] osTimerDelete failed, ret = %lx!!", + ret); + if (g_timer != NULL) + { + ret = osTimerDelete(g_timer); + } + g_timer = NULL; + return; + } + return; + } + + void SleepModel::Sleep_StopTimer(void) + { + // 检查定时器是否存在 + if (g_timer != NULL) + { + // 删除定时器并置为 NULL + osTimerStop(g_timer); + osStatus_t ret = osTimerDelete(g_timer); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "osTimerDelete failed, ret = %lx!!", ret); + } + g_timer = NULL; + } + } + /* -------------------------------------------------------------------------- */ + +#ifdef __cplusplus +#if __cplusplus + extern "C" + { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + + void custom_read_sleep_data(void) + { + memset(&sleep_data, 0, sizeof(SLEEP_T)); + read_sleep_data(&sleep_data); + } + + void custom_read_nap_data(void) + { + memset(&nap_data, 0, sizeof(NAP_T)); + read_nap_data(&nap_data); + } + + void custom_read_wear_data(void) + { + read_wear_data(); + } + + void custom_sleep_model_updata(void) + { + OHOS::SleepModel::GetInstance().ReInitData(); + } + // 更新睡眠数据 + void update_sleep_data(uint32_t sleep_timestamp, uint32_t wake_timestamp, + uint32_t totaltime) { + sleep_data.fall_asleep_timestamp = sleep_timestamp; + sleep_data.wake_up_timestamp = wake_timestamp; + sleep_data.total_time = totaltime; + sleep_update_timestamp = sleep_data.wake_up_timestamp; + } + // 更新小睡数据 + void update_nap_data(uint32_t sleep_timestamp, uint32_t wake_timestamp, + uint32_t totaltime) { + nap_data.fall_asleep_timestamp = sleep_timestamp; + nap_data.wake_up_timestamp = wake_timestamp; + nap_data.total_time = totaltime; + nap_update_timestamp = nap_data.wake_up_timestamp; + } + + +#ifdef __cplusplus +#if __cplusplus + } +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/src/SleepNapView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/src/SleepNapView.cpp new file mode 100644 index 000000000..d11921f95 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/src/SleepNapView.cpp @@ -0,0 +1,149 @@ +#include "sleep/include/SleepNapView.h" +#include "ConfigModel.h" +#include "common/image_cache_manager.h" +#include "sleep/include/SleepModel.h" +#include "string" +#include "uicomponents/UIComponents.h" +namespace OHOS { + +static SleepNapView *g_pSleepNapView{nullptr}; +static std::string restStr; +static std::string sleepStr; +static std::string wakeStr; +static std::string napsleepStr; +static std::string napwakeStr; +SleepNapView::SleepNapView() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepNapView::SleepNapView"); + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + SetViewIndex(0); // 视图索引 + + g_pSleepNapView = this; +} + +SleepNapView::~SleepNapView() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " SleepNapView::~SleepNapView"); + ClearAll(); + + g_pSleepNapView = nullptr; +} + +void SleepNapView::SleepDataRefresh() { + + int nap_hour = SleepModel::GetInstance().get_nap_hour(); + int nap_min = SleepModel::GetInstance().get_nap_min(); + + //小睡数据 + if (nap_hour != 0 || nap_min != 0) { + if (napsleep != nullptr && napwake != nullptr) { + napsleep->SetText((SleepModel::GetInstance().get_napsleep_str()).c_str()); + napwake->SetText((SleepModel::GetInstance().get_napwake_str()).c_str()); + } + } +} + +void SleepNapView::ClearAll() { + RemoveAll(); + + if (transverseline_1 != nullptr) { + delete transverseline_1; + transverseline_1 = nullptr; + } + if (transverseline_2 != nullptr) { + delete transverseline_2; + transverseline_2 = nullptr; + } + if (verticalline != nullptr) { + delete verticalline; + verticalline = nullptr; + } + + if (napsleeptitle != nullptr) { + delete napsleeptitle; + napsleeptitle = nullptr; + } + if (napwaketitle != nullptr) { + delete napwaketitle; + napwaketitle = nullptr; + } + if (napwake != nullptr) { + delete napwake; + napwake = nullptr; + } + if (napsleep != nullptr) { + delete napsleep; + napsleep = nullptr; + } + if (naptitle != nullptr) { + delete naptitle; + naptitle = nullptr; + } + if (apptitle != nullptr) { + delete apptitle; + apptitle = nullptr; + } +} + +SleepNapView *SleepNapView::GetInstance() { return g_pSleepNapView; } + + +bool SleepNapView::InitPage(void) { + /* ---------------------------------- 线条初始化 + * --------------------------------- */ + CreateLine(transverseline_1, 0, 169, 466, 2, "transverseline_1"); + CreateLine(transverseline_2, 0, 296, 466, 2, "transverseline_2"); + CreateLine(verticalline, 232, 191, 2, 82, "verticalline"); + /* -------------------------------- title初始化 + * -------------------------------- */ + //TODO:多国语言 + InitLabelExt(naptitle, 83, 90, 300, 35, "resttitle",STR_NAP, + DEFAULT_VECTOR_FONT_FILENAME_EN, 30); + InitLabelExt(napsleeptitle, 21, 203, 200, 35, "sleeptitle", STR_SLEEPTIME, + DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabelExt(napwaketitle, 213, 203, 300, 35, "waketitle", STR_WALKTIME, + DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabelExt(apptitle, 93, 300, 300, 200, "apptitle", STR_APPMORE, + DEFAULT_VECTOR_FONT_FILENAME, 26); + apptitle->SetTextColor(Color::Gray()); + /* ------------------------------- 数据label初始化 + * ------------------------------- */ + napsleepStr = "--"; + InitLabel(napsleep, 10, 238, 230, 47, "sleeplabel", napsleepStr.c_str(), + DEFAULT_VECTOR_FONT_FILENAME_EN, 40); + napsleep->SetTextColor(Color::GetColorFromRGBA(0x53, 0x20, 0xE2, 0xff)); + napwakeStr = "--"; + InitLabel(napwake, 245, 238, 230, 47, "wakelabel", napwakeStr.c_str(), + DEFAULT_VECTOR_FONT_FILENAME_EN, 40); + napwake->SetTextColor(Color::GetColorFromRGBA(0x53, 0x20, 0xE2, 0xff)); + /* -------------------------------------------------------------------------- + */ + /* -------------------------------- 将组件添加到根视图 + * ------------------------------- */ + Add(transverseline_1); + Add(transverseline_2); + Add(verticalline); + + Add(naptitle); + Add(napsleeptitle); + Add(napwaketitle); + Add(napsleep); + Add(napwake); + Add(apptitle); + + return true; +} + +bool SleepNapView::InitView(void *caller) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepNapView InitView %p", caller); + if (InitPage() == false) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepNapView::InitPage fail"); + return false; + } + SetDraggable(true); + SetTouchable(true); + SleepDataRefresh(); + return true; +} + +// 获取视图初始化状态 +bool SleepNapView::GetInitViewState(void) { return viewInitStatus; } +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/src/SleepTimeView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/src/SleepTimeView.cpp new file mode 100644 index 000000000..292c1d135 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/src/SleepTimeView.cpp @@ -0,0 +1,194 @@ +#include "sleep/include/SleepTimeView.h" +#include "ConfigModel.h" +#include "common/image_cache_manager.h" +#include "sleep/include/SleepModel.h" +#include "string" +#include "uicomponents/UIComponents.h" +namespace OHOS { + +static SleepTimeView *g_pSleepView{nullptr}; +static std::string restStr; +static std::string sleepStr; +static std::string wakeStr; +static constexpr char *upimagePath = "/user/res/Sleep/up.bin"; +SleepTimeView::SleepTimeView() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepTimeView::SleepTimeView"); + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + SetViewIndex(0); // 视图索引 + + g_pSleepView = this; +} + +SleepTimeView::~SleepTimeView() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " SleepTimeView::~SleepTimeView"); + ClearAll(); + + g_pSleepView = nullptr; +} + +void SleepTimeView::SleepDataRefresh() { + + int sleep_hour = SleepModel::GetInstance().get_sleep_hour(); + int sleep_min = SleepModel::GetInstance().get_sleep_min(); + int sleep_goal = SleepModel::GetInstance().get_sleep_goal(); + + // 有数据则刷新 + if (sleep_hour != 0 || sleep_min != 0) { + if (sleep != nullptr && wake != nullptr) { + sleep->SetText((SleepModel::GetInstance().get_rest_str()).c_str()); + wake->SetText((SleepModel::GetInstance().get_wake_str()).c_str()); + } + } + if (goal != nullptr) { + goal->SetText((SleepModel::GetInstance().get_goal_str()).c_str()); + } + // 更新目标时间 + if (goaltime != nullptr) { + UpdateLabel(goaltime, sleep_goal, STR_SLEEPMGOAL); + } +} + +void SleepTimeView::ClearAll() { + RemoveAll(); + if (resttitle != nullptr) { + delete resttitle; + resttitle = nullptr; + } + if (sleeptitle != nullptr) { + delete sleeptitle; + sleeptitle = nullptr; + } + if (waketitle != nullptr) { + delete waketitle; + waketitle = nullptr; + } + if (goaltime != nullptr) { + delete goaltime; + goaltime = nullptr; + } + if (goal != nullptr) { + delete goal; + goal = nullptr; + } + + if (sleep != nullptr) { + delete sleep; + sleep = nullptr; + } + if (wake != nullptr) { + delete wake; + wake = nullptr; + } + if (upiconimage != nullptr) { + delete upiconimage; + upiconimage = nullptr; + } + if (transverseline_1 != nullptr) { + delete transverseline_1; + transverseline_1 = nullptr; + } + if (transverseline_2 != nullptr) { + delete transverseline_2; + transverseline_2 = nullptr; + } + if (verticalline != nullptr) { + delete verticalline; + verticalline = nullptr; + } +} + +SleepTimeView *SleepTimeView::GetInstance() { return g_pSleepView; } + +bool SleepTimeView::InitPage(void) { + /* ---------------------------------- 线条初始化 + * --------------------------------- */ + if (transverseline_1 == nullptr) { + transverseline_1 = new UIImageView(); + } + transverseline_1->SetPosition(0, 169); + transverseline_1->Resize(466, 2); + transverseline_1->SetViewId("image1"); + transverseline_1->SetStyle(STYLE_BACKGROUND_COLOR, 0xff333333); + transverseline_1->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + transverseline_1->SetVisible(true); + + if (transverseline_2 == nullptr) { + transverseline_2 = new UIImageView(); + } + transverseline_2->SetPosition(232, 191); + transverseline_2->Resize(2, 82); + transverseline_2->SetViewId("image2"); + transverseline_2->SetStyle(STYLE_BACKGROUND_COLOR, 0xff333333); + transverseline_2->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + transverseline_2->SetVisible(true); + + if (verticalline == nullptr) { + verticalline = new UIImageView(); + } + verticalline->SetPosition(0, 296); + verticalline->Resize(466, 2); + verticalline->SetViewId("image1"); + verticalline->SetStyle(STYLE_BACKGROUND_COLOR, 0xff333333); + verticalline->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + verticalline->SetVisible(true); + InitImageView(upiconimage, 213, 420, 40, 40, "image", upimagePath); + + /* -------------------------------- title初始化 + * -------------------------------- */ + InitLabelExt(resttitle, 83, 50, 300, 35, "resttitle", STR_REATTIME, + DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabelExt(sleeptitle, 21, 203, 200, 35, "sleeptitle", STR_SLEEPTIME, + DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabelExt(waketitle, 213, 203, 300, 35, "waketitle", STR_WALKTIME, + DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabelExt(goaltime, 83, 350, 300, 50, "lablegoal", STR_SLEEPMGOAL, + DEFAULT_VECTOR_FONT_FILENAME, 30); + goaltime->SetTextColor(Color::Gray()); + /* ------------------------------- 数据label初始化 + * ------------------------------- */ + //DEFAULT_VECTOR_FONT_FILENAME_EN + restStr = "--"; + InitLabel(goal, 83, 90, 300, 50, "restlabel", restStr.c_str(), + DEFAULT_VECTOR_FONT_FILENAME_EN, 40); + // goal->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + goal->SetTextColor(Color::Gray()); + sleepStr = "--"; + InitLabel(sleep, 10, 238, 230, 47, "sleeplabel", sleepStr.c_str(), + DEFAULT_VECTOR_FONT_FILENAME_EN, 40); + sleep->SetTextColor(Color::GetColorFromRGBA(0x53, 0x20, 0xE2, 0xff)); + wakeStr = "--"; + InitLabel(wake, 245, 238, 230, 47, "wakelabel", wakeStr.c_str(), + DEFAULT_VECTOR_FONT_FILENAME_EN, 40); + wake->SetTextColor(Color::GetColorFromRGBA(0x53, 0x20, 0xE2, 0xff)); + + /* -------------------------------- 将组件添加到根视图 + * ------------------------------- */ + Add(resttitle); + Add(sleeptitle); + Add(waketitle); + Add(goaltime); + Add(goal); + Add(sleep); + Add(wake); + Add(transverseline_1); + Add(transverseline_2); + Add(verticalline); + Add(upiconimage); + return true; +} + +bool SleepTimeView::InitView(void *caller) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepTimeView InitView %p", caller); + if (InitPage() == false) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepTimeView::InitPage fail"); + return false; + } + SetDraggable(true); + SetTouchable(true); + SleepDataRefresh(); + return true; +} + +// 获取视图初始化状态 +bool SleepTimeView::GetInitViewState(void) { return viewInitStatus; } +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/src/SleepView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/src/SleepView.cpp new file mode 100644 index 000000000..cbc816902 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/sleep/src/SleepView.cpp @@ -0,0 +1,254 @@ +#include "sleep/include/SleepView.h" +#include "ConfigModel.h" +#include "common/image_cache_manager.h" +#include "languagecode/LanguageInit.h" +#include "sleep/include/SleepModel.h" +#include "uicomponents/UIComponents.h" +namespace OHOS { +static constexpr char *roomimagePath = "/user/res/Sleep/room.bin"; +static constexpr char *upimagePath = "/user/res/Sleep/up.bin"; +static constexpr const char *prossimagePath = "/user/res/step/step_b.bin"; + +static SleepView *g_pSleepView{nullptr}; +SleepView::SleepView() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepView::SleepView"); + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + SetViewIndex(0); // 视图索引 + + g_pSleepView = this; +} + +SleepView::~SleepView() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " SleepView::~SleepView"); + ClearAll(); + + g_pSleepView = nullptr; +} + +void SleepView::SleepDataRefresh() { + // 获取睡眠数据内存 + SleepModel &sleepModel = SleepModel::GetInstance(); + sleepModel.ReInitData(); + + int sleep_hour = sleepModel.get_sleep_hour(); + int sleep_min = sleepModel.get_sleep_min(); + int total_sleep = sleepModel.get_sleep_total(); + int sleep_goal = sleepModel.get_sleep_goal(); + + // 检查是否超过24小时 + if (sleep_hour >= 24) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "异常:睡眠时长超过24小时"); + return; + } + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "SleepDataRefresh %d %d sleep_goal:%d total_sleep:%d", + sleep_hour, sleep_min, sleep_goal * 60, total_sleep); + + // 补零操作 + std::string hour_str = (sleep_hour < 10) ? "0" + std::to_string(sleep_hour) + : std::to_string(sleep_hour); + std::string min_str = (sleep_min < 10) ? "0" + std::to_string(sleep_min) + : std::to_string(sleep_min); + + // 有数据才刷新 + if (sleep_hour != 0 || sleep_min != 0) { + // 更新时间显示 + if (time_hour != nullptr) { + time_hour->SetText(hour_str.c_str()); + } + if (time_minute != nullptr) { + time_minute->SetText(min_str.c_str()); + } + + // 计算进度百分比,确保目标睡眠时间不为零 + float progress_value = 0.0f; + if (sleep_goal > 0) { + progress_value = + static_cast(total_sleep) / (sleep_goal * 60); // 计算进度 + } + + // 日志输出进度百分比 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Progress value: %.2f%%", + progress_value * 100); // 显示为百分比 + + // 更新进度条 + circleProgress_->SetValue(progress_value * + 100); // 更新进度条值,范围为 0 到 100 + circleProgress_->SetCapType(CAP_ROUND); + } + + // 更新时间 + if (sleep_update_time != nullptr) { + std::string update_time = sleepModel.GetUpdateSleepTime(); + if (!update_time.empty()) // 检查返回值是否有效 + { + std::string update_time_str; + // TODO:多国语言 + if (ConfigModel::GetInstance()->GetLanguage() == ZH_CN) { + update_time_str = update_time + " 更新"; + } else { + update_time_str = update_time + " update"; + } + sleep_update_time->SetText(update_time_str.c_str()); + // UpdateLabel(sleep_update_time, sleep_goal, STR_SLEEPMGOAL); // TODO: + // 多国语言支持 + } + } + + // 刷新视图 + RootView::GetInstance()->Invalidate(); +} + +void SleepView::ClearAll() { + RemoveAll(); + if (circleProgress_ != nullptr) { + delete circleProgress_; + circleProgress_ = nullptr; + } + if (title != nullptr) { + delete title; + title = nullptr; + } + if (hour != nullptr) { + delete hour; + hour = nullptr; + } + if (minute != nullptr) { + delete minute; + minute = nullptr; + } + if (time_hour != nullptr) { + delete time_hour; + time_hour = nullptr; + } + if (time_minute != nullptr) { + delete time_minute; + time_minute = nullptr; + } + if (sleep_update_time != nullptr) { + delete sleep_update_time; + sleep_update_time = nullptr; + } + if (roomimage != nullptr) { + delete roomimage; + roomimage = nullptr; + } + if (upiconimage != nullptr) { + delete upiconimage; + upiconimage = nullptr; + } + if (progress_image != nullptr) { + delete progress_image; + progress_image = nullptr; + } +} + +SleepView *SleepView::GetInstance() { return g_pSleepView; } + +/*初始化界面*/ +bool SleepView::InitPage(void) { + /*初始化title*/ + InitLabelExt(title, 83, 50, 300, 35, "labletitle", STR_SLEEP_YESTERDAY, + DEFAULT_VECTOR_FONT_FILENAME, 30); + /*初始化单位*/ + InitLabelExt(hour, 157, 246, 75, 75, "lablehour", STR_HOUR, + DEFAULT_VECTOR_FONT_FILENAME, 26); + hour->SetTextColor(Color::Gray()); + InitLabelExt(minute, 295, 246, 100, 75, "lableminute", STR_MIN, + DEFAULT_VECTOR_FONT_FILENAME, 26); + minute->SetTextColor(Color::Gray()); + if (ConfigModel::GetInstance()->GetLanguage() != ZH_CN) { + //需要缩小 + title->SetFont(DEFAULT_VECTOR_FONT_FILENAME,26); + hour->SetFont(DEFAULT_VECTOR_FONT_FILENAME,24); + minute->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 24); + + minute->SetText("Min");//多国语言 + hour->SetText("Hour"); + } else { + minute->SetText("分钟"); + hour->SetText("小时"); + } + /*初始化image*/ + InitImageView(roomimage, 192, 127, 82, 82, "image", roomimagePath); + InitImageView(upiconimage, 213, 420, 40, 40, "image", upimagePath); + InitImageView(progress_image, 28, 80, 100, 100, "image", prossimagePath); + /*初始化目标时间*/ + // DEFAULT_VECTOR_FONT_FILENAME_EN + InitLabelExt(sleep_update_time, 83, 330, 300, 35, "lablegoal", STR_SLEEPMGOAL, + DEFAULT_VECTOR_FONT_FILENAME_EN, 30); + sleep_update_time->SetTextColor(Color::Gray()); + /*初始化睡眠时间*/ + time_hour = new UILabel(); + time_hour->SetPosition(84, 237); + time_hour->Resize(40, 75); + time_hour->SetViewId("time_hour"); + time_hour->SetText("--"); + time_hour->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + time_hour->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + time_hour->SetFont(GILROY_BOLD_FONT, 65); + + time_minute = new UILabel(); + time_minute->SetPosition(240, 237); + time_minute->Resize(40, 75); + time_minute->SetViewId("time_minute"); + time_minute->SetText("--"); + time_minute->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + time_minute->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + time_minute->SetFont(GILROY_BOLD_FONT, 65); + /* --------------------------------- 初始化进度条 + * --------------------------------- */ + circleProgress_ = new UICircleProgress(); + if (circleProgress_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "circleProgress new fail"); + return false; + } + circleProgress_->SetPosition(0, 0); + circleProgress_->Resize(466, 466); + circleProgress_->SetViewId("circleProgress1"); + circleProgress_->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + circleProgress_->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + circleProgress_->SetBackgroundStyle(STYLE_BACKGROUND_OPA, 0x00); + circleProgress_->SetBackgroundStyle(STYLE_BORDER_OPA, 0x00); + circleProgress_->SetBackgroundStyle(STYLE_LINE_OPA, 0x00); + circleProgress_->SetForegroundStyle(STYLE_BACKGROUND_COLOR, 0xff2195F6); + circleProgress_->SetForegroundStyle(STYLE_BORDER_COLOR, 0xff000000); + circleProgress_->SetForegroundStyle(STYLE_LINE_COLOR, 0xff5320e2); + circleProgress_->SetForegroundStyle(STYLE_LINE_WIDTH, 20); + circleProgress_->SetCenterPosition(233, 229); + circleProgress_->SetRadius(205); + circleProgress_->SetStartAngle(320); + circleProgress_->SetEndAngle(40); + circleProgress_->SetCapType(CAP_ROUND); + /* -------------------------------- 将组件添加到根视图 + * ------------------------------- */ + Add(progress_image); + Add(circleProgress_); + Add(title); + Add(hour); + Add(minute); + Add(time_hour); + Add(time_minute); + Add(sleep_update_time); + Add(upiconimage); + Add(roomimage); + + viewInitStatus = true; + return true; +} + +bool SleepView::InitView(void *caller) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepView InitView %p", caller); + if (InitPage() == false) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepView::InitPage fail"); + return false; + } + SleepDataRefresh(); // 刷新数据 + SetDraggable(true); + SetTouchable(true); + return true; +} + +bool SleepView::GetInitViewState(void) { return viewInitStatus; } +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/build/config/target_config/brandy/config.py b/code/sdk/build/config/target_config/brandy/config.py index 124d6a5d3..b8a32b94e 100644 --- a/code/sdk/build/config/target_config/brandy/config.py +++ b/code/sdk/build/config/target_config/brandy/config.py @@ -337,6 +337,7 @@ target = { 'BOARD_FD230', 'FT_SINGLE_UART', 'CONFIG_EFUSE_READ_TO_RAM', + # 'CUSTOM_UTILS', # 'CUSTOM_HID_SERVICE', # 'WEARABLE_LOG_DEBUG', 'SUPPORT_RC_CALIBRATION', diff --git a/code/sdk/zhihui/utils/custom_fileoperate_service.c b/code/sdk/zhihui/utils/custom_fileoperate_service.c index 2daeb3220..374f8ca9f 100644 --- a/code/sdk/zhihui/utils/custom_fileoperate_service.c +++ b/code/sdk/zhihui/utils/custom_fileoperate_service.c @@ -57,12 +57,12 @@ void store_sport_data(void){} //进行心率列表存储 void custom_save_sleep_data(void){} void custom_save_nap_data(void){} -void custom_read_sleep_data(void){} -void custom_read_nap_data(void){} -void custom_sleep_model_updata(void){} -void update_sleep_data(uint32_t sleep_timestamp,uint32_t wake_timestamp,uint32_t totaltime){} -void update_nap_data(uint32_t sleep_timestamp,uint32_t wake_timestamp,uint32_t totaltime){} -void custom_read_wear_data(void){} +//void custom_read_sleep_data(void){} +//void custom_read_nap_data(void){} +//void custom_sleep_model_updata(void){} +//void update_sleep_data(uint32_t sleep_timestamp,uint32_t wake_timestamp,uint32_t totaltime){} +//void update_nap_data(uint32_t sleep_timestamp,uint32_t wake_timestamp,uint32_t totaltime){} +//void custom_read_wear_data(void){} #ifndef FACTORYTEST_SERVICE // void factorytest_save_aging_data(void){} // void factorytest_read_aging_data(void){} -- 2.17.1