From dfe7170dbc182ee16ffef463aceb49c7f5015a79 Mon Sep 17 00:00:00 2001 From: Caisking Date: Thu, 8 Jan 2026 10:47:18 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E6=98=9F=E5=8E=86=E6=8F=90?= =?utf8?q?=E9=86=92=E7=95=8C=E9=9D=A2UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativelauncher/include/AppViewIDs.h | 1 + .../include/TraingEphemerisNotePresenter.h | 36 +++++ .../include/TraingEphemerisNoteView.h | 64 ++++++++ .../src/TraingEphemerisNotePresenter.cpp | 97 +++++++++++ .../src/TraingEphemerisNoteView.cpp | 153 ++++++++++++++++++ 5 files changed, 351 insertions(+) create mode 100644 code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/include/TraingEphemerisNotePresenter.h create mode 100644 code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/include/TraingEphemerisNoteView.h create mode 100644 code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingEphemerisNotePresenter.cpp create mode 100644 code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingEphemerisNoteView.cpp diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/fd272/nativeapp/nativelauncher/include/AppViewIDs.h index dc2a75348..f0fa0d7d4 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/fd272/nativeapp/nativelauncher/include/AppViewIDs.h @@ -103,6 +103,7 @@ typedef enum : uint16_t VIEW_TRAININGENDDATA, // 训练结束详细数据 VIEW_TRAINING_RECORD, // 训练记录 VIEW_TRAINING_GPSNOTE,// 训练GPS提醒 + VIEW_TRAINING_EPHEMERIS_NOTE,// 训练星历提醒 /* ---------------------------------- 训练列表 ---------------------------------- */ VIEW_TRAININGMORE, // 更多训练 VIEW_TRAININGLIMIT, // 极限运动列表 diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/include/TraingEphemerisNotePresenter.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/include/TraingEphemerisNotePresenter.h new file mode 100644 index 000000000..981865347 --- /dev/null +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/include/TraingEphemerisNotePresenter.h @@ -0,0 +1,36 @@ +#ifndef _TraingEphemerisNote_PRESENTER_H +#define _TraingEphemerisNote_PRESENTER_H + +#include "key/include/KeyInputListener.h" +#include "Presenter.h" +#include "TraingEphemerisNoteView.h" + +namespace OHOS +{ + class TraingEphemerisNoteView; + + class TraingEphemerisNotePresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + TraingEphemerisNotePresenter(); + virtual ~TraingEphemerisNotePresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static TraingEphemerisNotePresenter *GetInstance(); + + private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnDragEnd(UIView& view, const DragEvent& event) override; + }; +} // namespace OHOS + +#endif // TraingEphemerisNote_PRESENTER_H + diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/include/TraingEphemerisNoteView.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/include/TraingEphemerisNoteView.h new file mode 100644 index 000000000..9121aa6c4 --- /dev/null +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/include/TraingEphemerisNoteView.h @@ -0,0 +1,64 @@ +#ifndef _TraingEphemerisNote_VIEW_H +#define _TraingEphemerisNote_VIEW_H + +#include "View.h" +#include "components/icon_adapter.h" +#include "components/ui_button.h" +#include "components/ui_card_page.h" +#include "components/ui_chart.h" +#include "components/ui_image_animator.h" +#include "components/ui_image_view.h" +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_label_button_ext.h" +#include "components/ui_label_ext.h" +#include "components/ui_list.h" +#include "components/ui_view_group.h" +#include "ohos_types.h" +#include "traing/Training_UiConfig.h" +#include "traing/include/TraingModel.h" +#include "uicomponents/UIComponents.h" +#include "wearable_log.h" +#include + +#include "TraingEphemerisNotePresenter.h" +namespace OHOS { +#define BUTTONTRAIN "button1" // 去训练按钮 +#define BUTTONDOWNLOAD "button2" // 去下载按钮 + +class TraingEphemerisNotePresenter; +class TraingEphemerisNoteView : public View { + +public: + TraingEphemerisNoteView(); + virtual ~TraingEphemerisNoteView(); + static TraingEphemerisNoteView *GetInstance(void); + + void OnStart() override; + + void InitView(); + void DeInit(); + + void InitList(); + void PreLoad(void); + +private: + UIView::OnDragListener *draglistener{nullptr}; + TraingEphemerisNoteView(TraingEphemerisNoteView &&) = delete; + TraingEphemerisNoteView &operator=(TraingEphemerisNoteView &&) = delete; + + UIScrollView *scrollView1_ = nullptr; + + UILabelExt *label1_ = nullptr; + UILabelExt *label2_ = nullptr; + + UILabelButtonExt *button_back = nullptr; + UILabelButtonExt *button_download = nullptr; + + UIImageView *image1_ = nullptr; + UIImageView *image2_ = nullptr; + bool viewiInitStatus{false}; +}; +} // namespace OHOS +#endif // TraingEphemerisNote_PRESENTER_H + diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingEphemerisNotePresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingEphemerisNotePresenter.cpp new file mode 100644 index 000000000..aa26aadd6 --- /dev/null +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingEphemerisNotePresenter.cpp @@ -0,0 +1,97 @@ +#include "AppViewIDs.h" +#include "components/ui_label_ext.h" +#include "ui_resource_string.h" +#include "NativeAbility.h" + +#include +#include +#include +#include "traing/training_GPS/include/TraingEphemerisNotePresenter.h" +#include "ephemeris_download/include/EphemerisDownloadModel.h" +#include "traing/training_card/include/TraingCardPresenter.h" +#include "traing/include/TraingModel.h" +#include "traing/include/TraingNomalPresenter.h" + +#include "NativeRegisterManager.h" +namespace OHOS +{ + REGIST_SLICE(VIEW_TRAINING_EPHEMERIS_NOTE, TraingEphemerisNoteView, TraingEphemerisNotePresenter); + + // 当前Presenter属性实例化的内存指针 + static TraingEphemerisNotePresenter *g_pTraingEphemerisNotePresenter = nullptr; + + TraingEphemerisNotePresenter::TraingEphemerisNotePresenter() + { + g_pTraingEphemerisNotePresenter = this; + } + + TraingEphemerisNotePresenter::~TraingEphemerisNotePresenter() + { + g_pTraingEphemerisNotePresenter = nullptr; + } + + TraingEphemerisNotePresenter *TraingEphemerisNotePresenter::GetInstance() + { + return g_pTraingEphemerisNotePresenter; + } + + void TraingEphemerisNotePresenter::OnStart() + { + Presenter::OnStart(); + } + + void TraingEphemerisNotePresenter::OnPause(void) + { + Presenter::OnPause(); + } + + void TraingEphemerisNotePresenter::OnResume(void) + { + Presenter::OnResume(); + } + + void TraingEphemerisNotePresenter::OnStop(void) + { + Presenter::OnStop(); + } + + bool TraingEphemerisNotePresenter::OnDrag(UIView &view, const DragEvent &event) + { + return true; + } + + bool TraingEphemerisNotePresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) + { + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(preSlice); + } + UNUSED(view); + return true; + } + + bool TraingEphemerisNotePresenter::OnClick(UIView &view, const ClickEvent &event) + { + // 根据控件id查找是哪个控件触发了点击回调 + if (strcmp(view.GetViewId(), BUTTONTRAIN) == 0) + { + // 去训练按钮 - 直接进入运动卡片(跳过星历检查) + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGCRAD); + + // 启动运动相关资源 + ExerciseClass type = TraingModel::GetInstance()->GetSportId(); + TraingCardPresenter::GetInstance()->OpenSensor(type); + TraingModel::GetInstance()->SetSportOpenWay(false); + } + else if (strcmp(view.GetViewId(), BUTTONDOWNLOAD) == 0) + { + // 去下载按钮 - 跳转到星历下载界面 + NativeAbility::GetInstance().ChangeSlice(VIEW_EPHEMERIS_DOWNLOAD); + + TraingNomalPresenter::GetInstance()->CleanupGPSResources();//关闭GPS资源 + } + return true; + } +} // namespace OHOS + diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingEphemerisNoteView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingEphemerisNoteView.cpp new file mode 100644 index 000000000..ac51c3330 --- /dev/null +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingEphemerisNoteView.cpp @@ -0,0 +1,153 @@ +#include "traing/training_GPS/include/TraingEphemerisNoteView.h" + +#include "UiConfig.h" +#include "ui_resource_string.h" +#include "ui_resource_image.h" +#include "uicomponents/UIComponents.h" +#include "traing/Training_UiConfig.h" + +namespace OHOS +{ + + static TraingEphemerisNoteView *g_pTraingEphemerisNoteView{nullptr}; + + TraingEphemerisNoteView::TraingEphemerisNoteView() + { + g_pTraingEphemerisNoteView = this; + } + + TraingEphemerisNoteView::~TraingEphemerisNoteView() + { + DeInit(); + g_pTraingEphemerisNoteView = nullptr; + } + + TraingEphemerisNoteView *TraingEphemerisNoteView::GetInstance(void) + { + return g_pTraingEphemerisNoteView; + } + + /* InitView:初始化界面*/ + void TraingEphemerisNoteView::InitView() + { + // Add ScrollView to App + if (scrollView1_ == nullptr) + { + scrollView1_ = new UIScrollView(); + } + scrollView1_->SetPosition(0, 0); + scrollView1_->Resize(466, 466); + scrollView1_->SetViewId("scrollView1"); + scrollView1_->SetReboundSize(100); + scrollView1_->SetScrollBlankSize(52); + scrollView1_->SetHorizontalScrollState(false); + AddViewToRootContainer(scrollView1_); + scrollView1_->SetVisible(true); + + // 初始化Image - 警告图标 + InitImageView(image1_, 193, 111, 80, 80, "image1", WARNING_IMAGE); + scrollView1_->Add(image1_); + + // 初始化button - 去训练按钮 + InitButtonExt(button_back, 118, 434, 230, 80, BUTTONTRAIN, STR_SET_TARGET, 30); + button_back->SetText("去训练"); + scrollView1_->Add(button_back); + button_back->SetOnClickListener(presenter_); + + // 初始化button - 去下载按钮 + InitButtonExt(button_download, 118, 334, 230, 80, BUTTONDOWNLOAD, STR_EPHEMERIS_DOWNLOAD, 30); + button_download->SetText("去下载"); + button_download->SetStyle(STYLE_BACKGROUND_COLOR, 0xff4fc34c); + scrollView1_->Add(button_download); + button_download->SetOnClickListener(presenter_); + + // 初始化Lable - 标题 + InitLabel(label1_, 133, 52, 200, 60, "label1", "星历未下载", DEFAULT_VECTOR_FONT_FILENAME, 30); + // 初始化Lable - 说明文字 + InitLabel(label2_, 33, 215, 400, 90, "label2", "星历数据未下载或已过期,建议先下载星历数据后再开始训练", DEFAULT_VECTOR_FONT_FILENAME, 30); + + scrollView1_->Add(label1_); + scrollView1_->Add(label2_); + + // Add ImageView to App + if (image2_ == nullptr) + { + image2_ = new UIImageView(); + } + image2_->SetPosition(181, 500); + image2_->Resize(100, 100); + image2_->SetViewId("image7"); + scrollView1_->Add(image2_); + image2_->SetVisible(true); + } + + /* DeInit:删除组件 */ + void TraingEphemerisNoteView::DeInit() + { + if (scrollView1_ != nullptr) + { + scrollView1_->RemoveAll(); + if (image1_ != nullptr) + { + delete image1_; + image1_ = nullptr; + } + if (button_back != nullptr) + { + delete button_back; + button_back = nullptr; + } + if(button_download != nullptr) + { + delete button_download; + button_download = nullptr; + } + if (label1_ != nullptr) + { + delete label1_; + label1_ = nullptr; + } + if (label2_ != nullptr) + { + delete label2_; + label2_ = nullptr; + } + if (image2_ != nullptr) + { + delete image2_; + image2_ = nullptr; + } + + delete scrollView1_; + scrollView1_ = nullptr; + } + } + + void TraingEphemerisNoteView::PreLoad(void) + { + if (!viewiInitStatus) + { + InitView(); + viewiInitStatus = true; + } + } + + void TraingEphemerisNoteView::OnStart() + { + // 创建 draglistener 实例并设置为拖动监听器 + UIView::OnDragListener *draglistener = static_cast(TraingEphemerisNotePresenter::GetInstance()); + if (draglistener == nullptr) + { + return; + } + GetRootContainer()->SetOnDragListener(draglistener); + + GetRootContainer()->SetTouchable(true); + GetRootContainer()->SetDraggable(true); + + PreLoad(); + } + + +} // namespace OHOS + -- 2.17.1