From e6a5f533637de25fb964b60ed64e2e708d35f395 Mon Sep 17 00:00:00 2001 From: maomao <2144439972@qq.com> Date: Mon, 21 Apr 2025 14:40:51 +0800 Subject: [PATCH] =?utf8?q?=E3=80=90=E6=97=B6=E9=97=B4=E8=AE=BE=E7=BD=AE?= =?utf8?q?=E3=80=91UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 11 ++- .../include/SetTimeFormatModel.h | 37 +++++++ .../include/SetTimeFormatPresenter.h | 32 ++++++ .../include/SetTimeFormatView.h | 38 ++++++++ .../src/SetTimeFormatModel.cpp | 40 ++++++++ .../src/SetTimeFormatPresenter.cpp | 55 +++++++++++ .../set_time_format/src/SetTimeFormatView.cpp | 97 +++++++++++++++++++ 7 files changed, 309 insertions(+), 1 deletion(-) create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/set_time_format/include/SetTimeFormatModel.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/set_time_format/include/SetTimeFormatPresenter.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/set_time_format/include/SetTimeFormatView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/set_time_format/src/SetTimeFormatModel.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/set_time_format/src/SetTimeFormatPresenter.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/set_time_format/src/SetTimeFormatView.cpp diff --git a/.vscode/settings.json b/.vscode/settings.json index 68189f026..7918d6713 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -74,6 +74,15 @@ "mag_service.h": "c", "mmc5603_hal.h": "c", "clocks_config.h": "c", - "clocks_types.h": "c" + "clocks_types.h": "c", + "thread": "cpp", + "__node_handle": "cpp", + "atomic": "cpp", + "deque": "cpp", + "__memory": "cpp", + "locale": "cpp", + "optional": "cpp", + "system_error": "cpp", + "vector": "cpp" } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_time_format/include/SetTimeFormatModel.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_time_format/include/SetTimeFormatModel.h new file mode 100644 index 000000000..73141650c --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_time_format/include/SetTimeFormatModel.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) CompanyNameMagicTag 2024. All rights reserved. + * Description: SetTimeFormatModel.h + * Author: + * Create: 2024-06-06 + */ + +#ifndef SET_time_format_MODEL_H +#define SET_time_format_MODEL_H +#include "components/ui_view.h" + +namespace OHOS { + +enum class TimeFormat { + TIME_FORMAT_24H, // 24小时制 + TIME_FORMAT_12H, // 12小时制 + MAX_FORMAT_NUM, +}; + +class SetTimeFormatModel { +public: + static SetTimeFormatModel &GetInstance() { + static SetTimeFormatModel model; + return model; + } + + void SetStyle(TimeFormat style); + TimeFormat GetTimeStyle(); + +private: + SetTimeFormatModel(); + ~SetTimeFormatModel(); + SetTimeFormatModel(const SetTimeFormatModel &) = delete; + SetTimeFormatModel &operator=(const SetTimeFormatModel &) = delete; +}; +} // namespace OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_time_format/include/SetTimeFormatPresenter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_time_format/include/SetTimeFormatPresenter.h new file mode 100644 index 000000000..dd91b3272 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_time_format/include/SetTimeFormatPresenter.h @@ -0,0 +1,32 @@ + + +#ifndef SET_TimeFormat_PRESENTER_H +#define SET_TimeFormat_PRESENTER_H + +#include "components/ui_view.h" +#include "Presenter.h" + +#include "set_time_format/include/SetTimeFormatModel.h" +#include "set_time_format/include/SetTimeFormatView.h" +#include "set_time_format/include/SetTimeFormatPresenter.h" +namespace OHOS +{ + class SetTimeFormatModel; + class SetTimeFormatView; + class SetTimeFormatPresenter : public Presenter, + public UIView::OnClickListener, + public RootView::OnKeyActListener, + public UIView::OnDragListener + { + public: + SetTimeFormatPresenter(); + ~SetTimeFormatPresenter(); + SetTimeFormatPresenter(const SetTimeFormatPresenter &) = delete; + SetTimeFormatPresenter &operator=(const SetTimeFormatPresenter &) = 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 \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_time_format/include/SetTimeFormatView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_time_format/include/SetTimeFormatView.h new file mode 100644 index 000000000..7c6cf2887 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_time_format/include/SetTimeFormatView.h @@ -0,0 +1,38 @@ + + +#ifndef SET_Time_Format_VIEW_H +#define SET_Time_Format_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 "set_time_format/include/SetTimeFormatModel.h" + +namespace OHOS { +class SetTimeFormatPresenter; +class SetTimeFormatView : public View { +public: + SetTimeFormatView(); + ~SetTimeFormatView() override; + SetTimeFormatView(const SetTimeFormatView &) = delete; + SetTimeFormatView &operator=(const SetTimeFormatView &) = delete; + + void OnStart() override; + bool SetTimeFormatInit(); + void OnClick(UIView &view); + +private: + UILabelExt labelTitle_; + UILabelExt labelFormat24H_; + UIToggleButton btnFormat24H_; + UIImageView Format24H_Image_; + UILabelExt labelNote_; +}; +} // OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_time_format/src/SetTimeFormatModel.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_time_format/src/SetTimeFormatModel.cpp new file mode 100644 index 000000000..e119ae65c --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_time_format/src/SetTimeFormatModel.cpp @@ -0,0 +1,40 @@ + +#include "set_time_format/include/SetTimeFormatModel.h" + +#include "custom_runtime.h" +#include "custom_utils.h" + +#include "wearable_log.h" + +namespace OHOS { + +//设置时间格式 +void SetTimeFormatModel::SetStyle(TimeFormat style) { + // 12小时显示 + if (style == TimeFormat::TIME_FORMAT_12H) { + uapi_dev_runtime_set_time_hour_show_model(12); + WEARABLE_LOGE("SetTimeFormatModel", "SetStyle: 12H"); + } + // 24小时显示 + else if (style == TimeFormat::TIME_FORMAT_24H) { + uapi_dev_runtime_set_time_hour_show_model(24); + WEARABLE_LOGE("SetTimeFormatModel", "SetStyle: 24H"); + } + + return; +} +//获取时间格式 +TimeFormat SetTimeFormatModel::GetTimeStyle() { + if (uapi_dev_runtime_get_time_hour_show_model() == 24) { + WEARABLE_LOGE("SetTimeFormatModel", "GetStyle: 24H"); + return TimeFormat::TIME_FORMAT_24H; + } else { + WEARABLE_LOGE("SetTimeFormatModel", "GetStyle: 12H"); + return TimeFormat::TIME_FORMAT_12H; + } +} + +SetTimeFormatModel::SetTimeFormatModel() {} + +SetTimeFormatModel::~SetTimeFormatModel() {} +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_time_format/src/SetTimeFormatPresenter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_time_format/src/SetTimeFormatPresenter.cpp new file mode 100644 index 000000000..1da95d3d1 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_time_format/src/SetTimeFormatPresenter.cpp @@ -0,0 +1,55 @@ + +#include "set_time_format/include/SetTimeFormatPresenter.h" +#include "set_time_format/include/SetTimeFormatModel.h" +#include "set_time_format/include/SetTimeFormatView.h" + +#include "KeyInputListener.h" +#include "common/key_code.h" +#include "custom_utils.h" + +#include "AppViewIDs.h" +#include "NativeAbility.h" + +#include "NativeRegisterManager.h" + +namespace OHOS { + REGIST_SLICE( VIEW_SET_TIME_FORMAT, SetTimeFormatView, SetTimeFormatPresenter); + + +SetTimeFormatPresenter::SetTimeFormatPresenter() { + Attach(&SetTimeFormatModel::GetInstance()); +} + +SetTimeFormatPresenter::~SetTimeFormatPresenter() { + +} + +bool SetTimeFormatPresenter::OnClick(UIView &view, const ClickEvent &event) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetTimeFormatPresenter::OnClick"); + view_->OnClick(view); + return true; +} + +bool SetTimeFormatPresenter::OnDrag(UIView &view, const DragEvent &event) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetTimeFormatPresenter::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 SetTimeFormatPresenter::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 \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_time_format/src/SetTimeFormatView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_time_format/src/SetTimeFormatView.cpp new file mode 100644 index 000000000..f163dcbce --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_time_format/src/SetTimeFormatView.cpp @@ -0,0 +1,97 @@ +/*** + * @Date: 2024-07-05 11:09:20 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-09-05 18:09:22 + * @FilePath: + * /FD230/code/sdk/application/wearable/fd230app/nativeui/set_dial_style/src/SetTimeFormatView.cpp + */ + +#include "set_time_format/include/SetTimeFormatView.h" +#include "set_time_format/include/SetTimeFormatModel.h" +#include "set_time_format/include/SetTimeFormatPresenter.h" + +#include "UiConfig.h" +#include "ui_resource_string.h" +#include "components/ui_scroll_view.h" +namespace OHOS { +SetTimeFormatView::SetTimeFormatView() {} + +SetTimeFormatView::~SetTimeFormatView() {} + +void SetTimeFormatView::OnStart() { + + if (!SetTimeFormatInit()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HeartResultView::InitHeartView fail"); + } + + GetRootContainer()->SetDraggable(true); + GetRootContainer()->SetPosition(0, 0, 466, 466); + GetRootContainer()->SetOnDragListener(presenter_); + + GetRootContainer()->SetTouchable(true); +} + +bool SetTimeFormatView::SetTimeFormatInit() { + + Format24H_Image_.SetPosition(43, 120, 380, 100); + Format24H_Image_.SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + Format24H_Image_.SetStyle(STYLE_BACKGROUND_OPA, 0xff); + Format24H_Image_.SetStyle(STYLE_BORDER_RADIUS, 100); + AddViewToRootContainer(&Format24H_Image_); + + labelTitle_.SetPosition(83, 50, 300, 60); + labelTitle_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + // labelTitle_.SetTextId(STR_BROWSING_SPECIAL_EFFECTS); + labelTitle_.SetTextId(STR_TIME_SET); // TODO:多国语言 + labelTitle_.SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); // 居中 + labelTitle_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + AddViewToRootContainer(&labelTitle_); + + labelFormat24H_.SetPosition(90, 153, 200, 60); + labelFormat24H_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + // labelFormat24H_.SetTextId(STR_OVERLAY_FLOW); + labelFormat24H_.SetTextId(STR_FORMAT); // TODO:多国语言 + labelFormat24H_.SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + labelFormat24H_.SetRollSpeed(23); + AddViewToRootContainer(&labelFormat24H_); + + btnFormat24H_.SetPosition(298, 145, 100, 50); + btnFormat24H_.SetImages(PNG_TOGGLEBUTTON_ON_IMAGE, + PNG_TOGGLEBUTTON_OFF_IMAGE); + AddViewToRootContainer(&btnFormat24H_); + + labelNote_.SetPosition(53, 240, 360, 100); + labelNote_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20); + labelNote_.SetTextId(STR_FORMAT_NOTE); + AddViewToRootContainer(&labelNote_); + + const TimeFormat style = SetTimeFormatModel::GetInstance().GetTimeStyle(); + if (style == TimeFormat::TIME_FORMAT_24H) { + btnFormat24H_.SetState(true); + } else { + btnFormat24H_.SetState(false); + } + + btnFormat24H_.SetOnClickListener(presenter_); + return true; +} + + + +void SetTimeFormatView::OnClick(UIView &view) { + const UIToggleButton *ptr = dynamic_cast(&view); + if (ptr == nullptr) { + return; + } + if (ptr->GetState() == true) { + btnFormat24H_.SetState(true); + SetTimeFormatModel::GetInstance().SetStyle(TimeFormat::TIME_FORMAT_24H); + } else { + btnFormat24H_.SetState(false); + SetTimeFormatModel::GetInstance().SetStyle(TimeFormat::TIME_FORMAT_12H); + } + // 切换到切换表盘Slice + // NativeAbility::GetInstance().ChangeSlice(VIEW_SET_DIAL); +} +} // namespace OHOS \ No newline at end of file -- 2.17.1