From: xue <2144439972@qq.com> Date: Tue, 26 Aug 2025 06:10:53 +0000 (+0800) Subject: 增加久坐提醒开关 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=260a49ca65148977202ed9c76ce1cdc90f1df3c9;p=mirrors%2FFD230.git 增加久坐提醒开关 --- diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index 4fd2a7094..091704489 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -432,6 +432,9 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_time_format/src/SetTimeFormatModel.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_time_format/src/SetTimeFormatPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/set_time_format/src/SetTimeFormatView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/sedentary_setting/src/SedentarySettingModel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/sedentary_setting/src/SedentarySettingPresenter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/sedentary_setting/src/SedentarySettingView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/key/src/KeyInputListener.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/screennotify/src/ui_screennotify.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/heart_blood/BloodCardView.cpp diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h index bc5699b41..175d9ab67 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h @@ -155,6 +155,7 @@ typedef enum : uint16_t VIEW_SAFE_MODE, // 安全模式 VIEW_ASSISTANT, // 智能助手 VIEW_SET_TIME_FORMAT,// 时间格式 + VIEW_SET_SEDENTARY, // 久坐提醒设置 /*表盘功能相关VIEW_ID 请勿移动 请勿在下方增加slice*/ VIEW_DIAL_FUN_ID = 200, VIEW_GOAL, // 步数 diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h index 0190fa511..ae7264c4f 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h @@ -124,6 +124,7 @@ namespace OHOS void InitSafeModeSlice(void); void InitAssistantSlice(void); void InitSetTimeFormatSlice(void); + void InitSedentarySettingSlice(void); /* -------------------------------------------------------------------------- */ // void InitPhoneSlice(void); void InitPhoneCallSlice(void); diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index 2bfe381f0..68174ffda 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -150,6 +150,10 @@ /*时间格式显示*/ #include "set_time_format/include/SetTimeFormatView.h" #include "set_time_format/include/SetTimeFormatPresenter.h" +/*久坐提醒*/ +#include "sedentary_setting/include/SedentarySettingView.h" +#include "sedentary_setting/include/SedentarySettingPresenter.h" +#include "sedentary_setting/include/SedentarySettingModel.h" /*画布组件测试*/ #include "canvastest/include/CanvasView.h" #include "canvastest/include/CanvasPresenter.h" @@ -505,6 +509,8 @@ namespace OHOS {VIEW_SLEEP, &NativeLauncher::InitSleepSlice}, /*设置表盘样式*/ {VIEW_SET_DIAL_STYLE, &NativeLauncher::InitSetDialStyleSlice}, + /*久坐提醒设置*/ + {VIEW_SET_SEDENTARY, &NativeLauncher::InitSedentarySettingSlice}, /*心率周期检测*/ //{VIEW_SET_HEART, &NativeLauncher::InitSetHeartSlice}, /*密码锁*/ @@ -1814,6 +1820,17 @@ namespace OHOS } NativeAbility::GetInstance().AddSliceProxy(VIEW_SET_DIAL_STYLE, setDialStyleView); } + void NativeLauncher::InitSedentarySettingSlice(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitSedentarySettingSlice"); + SliceProxy *sedentarySettingView = new AbilitySliceProxy; + if (sedentarySettingView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sedentarySettingView"); + return; + } + NativeAbility::GetInstance().AddSliceProxy(VIEW_SET_SEDENTARY, sedentarySettingView); + } void NativeLauncher::InitScheduleSlice(void) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/sedentary_setting/include/SedentarySettingModel.h b/code/sdk/application/wearable/fd230app/nativeui/sedentary_setting/include/SedentarySettingModel.h new file mode 100644 index 000000000..f9adb80b6 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/sedentary_setting/include/SedentarySettingModel.h @@ -0,0 +1,30 @@ +#ifndef SEDENTARY_SETTING_MODEL_H_ +#define SEDENTARY_SETTING_MODEL_H_ + +#include "components/ui_view.h" + +namespace OHOS { + +class SedentarySettingModel { +public: + static SedentarySettingModel &GetInstance() + { + static SedentarySettingModel inst; + return inst; + } + + void SetSwitch(bool enable); + bool GetSwitch(); + +private: + SedentarySettingModel() = default; + ~SedentarySettingModel() = default; + SedentarySettingModel(const SedentarySettingModel &) = delete; + SedentarySettingModel &operator=(const SedentarySettingModel &) = delete; +}; + +} // namespace OHOS + +#endif + + diff --git a/code/sdk/application/wearable/fd230app/nativeui/sedentary_setting/include/SedentarySettingPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/sedentary_setting/include/SedentarySettingPresenter.h new file mode 100644 index 000000000..1a2330e66 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/sedentary_setting/include/SedentarySettingPresenter.h @@ -0,0 +1,34 @@ +#ifndef SEDENTARY_SETTING_PRESENTER_H_ +#define SEDENTARY_SETTING_PRESENTER_H_ + +#include "components/ui_view.h" +#include "key/include/KeyInputListener.h" +#include "Presenter.h" + +#include "sedentary_setting/include/SedentarySettingModel.h" +#include "sedentary_setting/include/SedentarySettingView.h" + +namespace OHOS +{ + class SedentarySettingModel; + class SedentarySettingView; + class SedentarySettingPresenter : public Presenter, + public UIView::OnClickListener, + public RootView::OnKeyActListener, + public UIView::OnDragListener + { + public: + SedentarySettingPresenter(); + ~SedentarySettingPresenter(); + SedentarySettingPresenter(const SedentarySettingPresenter &) = delete; + SedentarySettingPresenter &operator=(const SedentarySettingPresenter &) = delete; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 + }; + +} // OHOS +#endif + + + diff --git a/code/sdk/application/wearable/fd230app/nativeui/sedentary_setting/include/SedentarySettingView.h b/code/sdk/application/wearable/fd230app/nativeui/sedentary_setting/include/SedentarySettingView.h new file mode 100644 index 000000000..d71cfb0c1 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/sedentary_setting/include/SedentarySettingView.h @@ -0,0 +1,42 @@ +#ifndef SEDENTARY_SETTING_VIEW_H_ +#define SEDENTARY_SETTING_VIEW_H_ + +#include "components/ui_button.h" +#include "components/ui_label.h" +#include "components/ui_toggle_button.h" +#include "components/ui_view.h" +#include "components/ui_view_group.h" + +#include "View.h" +#include "components/ui_image_view.h" +#include "components/ui_label_ext.h" + +#include "sedentary_setting/include/SedentarySettingModel.h" + +namespace OHOS { +class SedentarySettingPresenter; +class SedentarySettingView : public View { +public: + SedentarySettingView(); + ~SedentarySettingView() override; + SedentarySettingView(const SedentarySettingView &) = delete; + SedentarySettingView &operator=(const SedentarySettingView &) = delete; + + void OnStart() override; + void OnSetUpView() override; + void OnStop() override; + void OnClick(UIView &view); + +private: + UILabelExt labelTitle_; + + UILabelExt labelSedentary_; + UIToggleButton btnSedentary_; + UIImageView Sedentary_Image_; + + UILabelExt labelNote_; +}; +} // OHOS +#endif + + diff --git a/code/sdk/application/wearable/fd230app/nativeui/sedentary_setting/src/SedentarySettingModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/sedentary_setting/src/SedentarySettingModel.cpp new file mode 100644 index 000000000..cb120e008 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/sedentary_setting/src/SedentarySettingModel.cpp @@ -0,0 +1,19 @@ +#include "sedentary_setting/include/SedentarySettingModel.h" + +#include "custom_runtime.h" + +namespace OHOS { + +void SedentarySettingModel::SetSwitch(bool enable) +{ + uapi_dev_runtime_set_sedentary_status(enable ? 1 : 0); +} + +bool SedentarySettingModel::GetSwitch() +{ + return uapi_dev_runtime_get_sedentary_status() ? true : false; +} + +} // namespace OHOS + + diff --git a/code/sdk/application/wearable/fd230app/nativeui/sedentary_setting/src/SedentarySettingPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/sedentary_setting/src/SedentarySettingPresenter.cpp new file mode 100644 index 000000000..433a0825b --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/sedentary_setting/src/SedentarySettingPresenter.cpp @@ -0,0 +1,46 @@ +#include "sedentary_setting/include/SedentarySettingPresenter.h" +#include "KeyInputListener.h" +#include "common/key_code.h" +#include "custom_utils.h" + +#include "AppViewIDs.h" +#include "NativeAbility.h" + +namespace OHOS { +SedentarySettingPresenter::SedentarySettingPresenter() { + Attach(&SedentarySettingModel::GetInstance()); +} + +SedentarySettingPresenter::~SedentarySettingPresenter() {} + +bool SedentarySettingPresenter::OnClick(UIView &view, const ClickEvent &event) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SedentarySettingPresenter::OnClick"); + view_->OnClick(view); + return true; +} + +bool SedentarySettingPresenter::OnDrag(UIView &view, const DragEvent &event) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SedentarySettingPresenter::OnDrag"); + UNUSED(view); + if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && + (event.GetDeltaX() > X_DRAG_OFFSET) && + (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { + NativeAbility::GetInstance().Back(); + } + return true; +} + +bool SedentarySettingPresenter::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; +} +} // namespace OHOS + + diff --git a/code/sdk/application/wearable/fd230app/nativeui/sedentary_setting/src/SedentarySettingView.cpp b/code/sdk/application/wearable/fd230app/nativeui/sedentary_setting/src/SedentarySettingView.cpp new file mode 100644 index 000000000..9e916f2c5 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/sedentary_setting/src/SedentarySettingView.cpp @@ -0,0 +1,97 @@ +#include "sedentary_setting/include/SedentarySettingView.h" +#include "sedentary_setting/include/SedentarySettingModel.h" +#include "sedentary_setting/include/SedentarySettingPresenter.h" + +#include "UiConfig.h" +#include "ui_resource_string.h" +#include "components/ui_scroll_view.h" +#include "wearable_log.h" + +namespace OHOS { +SedentarySettingView::SedentarySettingView() {} + +SedentarySettingView::~SedentarySettingView() {} + +void SedentarySettingView::OnStart() { + View::OnStart(); + SetContainerView(new UIViewGroup); + if (container_ == nullptr) { + return; + } + container_->SetDraggable(true); + container_->SetPosition(0, 0, 466, 466); + container_->SetOnDragListener(presenter_); + // 增加按键监听 + RootView::OnKeyActListener *keyactListener = + (RootView::OnKeyActListener *)(presenter_); + RootView::GetInstance()->SetOnKeyActListener(keyactListener); + container_->SetTouchable(true); +} + +void SedentarySettingView::OnSetUpView() { + if (container_ == nullptr) { + return; + } + View::OnSetUpView(); + + Sedentary_Image_.SetPosition(43, 120, 380, 100); + Sedentary_Image_.SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + Sedentary_Image_.SetStyle(STYLE_BACKGROUND_OPA, 0xff); + Sedentary_Image_.SetStyle(STYLE_BORDER_RADIUS, 100); + container_->Add(&Sedentary_Image_); + + labelTitle_.SetPosition(83, 50, 300, 60); + labelTitle_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + // labelTitle_.SetTextId(STR_BROWSING_SPECIAL_EFFECTS); + labelTitle_.SetText("久坐设置"); + labelTitle_.SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); // 居中 + labelTitle_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + container_->Add(&labelTitle_); + + labelSedentary_.SetPosition(90, 153, 200, 60); + labelSedentary_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + labelSedentary_.SetText("久坐提醒"); // TODO:多国语言 + labelSedentary_.SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + labelSedentary_.SetRollSpeed(23); + container_->Add(&labelSedentary_); + + btnSedentary_.SetPosition(298, 145, 100, 50); + btnSedentary_.SetImages(PNG_TOGGLEBUTTON_ON_IMAGE, + PNG_TOGGLEBUTTON_OFF_IMAGE); + container_->Add(&btnSedentary_); + + labelNote_.SetPosition(53, 240, 360, 100); + labelNote_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20); + labelNote_.SetText("注:打开后将会在长时间坐姿时,自动开启提醒"); + container_->Add(&labelNote_); + + btnSedentary_.SetState( SedentarySettingModel::GetInstance().GetSwitch()); + + btnSedentary_.SetOnClickListener(presenter_); +} + +void SedentarySettingView::OnStop() { + View::OnStop(); + if (container_ != nullptr) { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } +} + +void SedentarySettingView::OnClick(UIView &view) { + const UIToggleButton *ptr = dynamic_cast(&view); + if (ptr == nullptr) { + return; + } + if (ptr->GetState() == true) { + btnSedentary_.SetState(true); + SedentarySettingModel::GetInstance().SetSwitch(true); + } else { + btnSedentary_.SetState(false); + SedentarySettingModel::GetInstance().SetSwitch(false); + } + // 切换到切换表盘Slice + // NativeAbility::GetInstance().ChangeSlice(VIEW_SET_DIAL); +} +} // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemView.h b/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemView.h index b22d6ae13..fa3167871 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemView.h @@ -25,6 +25,7 @@ #include "system/include/SystemShutdown.h" #include "system/include/SystemRestart.h" #include "rebootandshutdown/include/ShutDownImageAnimatorView.h" +#include "sedentary_setting/include/SedentarySettingView.h" namespace OHOS { static constexpr const char *ABOUT_THE_WATCH = "AboutTheWatchButton"; // 关于手表 @@ -36,6 +37,7 @@ namespace OHOS static constexpr const char *SHUTDOWN = "ShutdownButton"; // 关机 static constexpr const char *FACTORY_RESET = "FactoryResetButton"; // 恢复出厂设置 static constexpr const char *SET_TIME_FORMAT = "SetTimeFormatButton"; // 设置时间格式 + static constexpr const char *SET_SEDENTARY = "SetSedentaryButton"; // 设置久坐提醒 typedef enum { diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemPresenter.cpp index 59931d786..dd21746a0 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemPresenter.cpp @@ -169,6 +169,11 @@ namespace OHOS { NativeAbility::GetInstance().EnterSlice(VIEW_SET_TIME_FORMAT); return true; + } + else if (strcmp(view.GetViewId(), SET_SEDENTARY) == 0) // 点击进入设置久坐提醒 + { + NativeAbility::GetInstance().EnterSlice(VIEW_SET_SEDENTARY); + return true; } else if (strcmp(view.GetViewId(), SYSTEM_UPGRADE) == 0) // 点击进入系统升级视图 { diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemView.cpp b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemView.cpp index 4fd654369..c89b58d9d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemView.cpp @@ -173,11 +173,12 @@ namespace OHOS {153, STR_ABOUT_WATCH}, // {273, STR_SYSTEM_UPDATE}, {273, STR_TIME_FORMAT_SET}, - {393, STR_WATCH_QR_CODE}, - {513, STR_SYSTEM_LANGUAGE}, - {633, STR_RESTART}, - {753, STR_SHUTDOWN}, - {873, STR_FACTORY_RESET}, + {393, STR_TIME_FORMAT_SET}, + {513, STR_WATCH_QR_CODE}, + {633, STR_SYSTEM_LANGUAGE}, + {753, STR_RESTART}, + {873, STR_SHUTDOWN}, + {993, STR_FACTORY_RESET}, }; labelConfig = { .left = 90, @@ -219,6 +220,7 @@ namespace OHOS ButtonSetup buttonSetups[] = { {120, ABOUT_THE_WATCH}, // {240, SYSTEM_UPGRADE}, + {240, SET_SEDENTARY}, {300, SET_TIME_FORMAT}, {360, WATCH_QR_CODE}, {480, SYSTEM_LANGUAGE},