From 9971dffb2e551a65148c30b4660ef0767d31b2b2 Mon Sep 17 00:00:00 2001 From: Caisking Date: Tue, 30 Sep 2025 16:09:29 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96=E6=98=9F=E5=8E=86=E4=B8=8B?= =?utf8?q?=E8=BD=BD=E4=BA=A4=E4=BA=92UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../include/EphemerisDownloadModel.h | 3 + .../include/EphemerisDownloadPresenter.h | 21 +++++-- .../src/EphemerisDownloadModel.cpp | 63 +++++++++++++++++++ .../src/EphemerisDownloadPresenter.cpp | 35 ++++++++--- .../src/EphemerisDownloadView.cpp | 22 +++++-- 5 files changed, 125 insertions(+), 19 deletions(-) diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/ephemeris_download/include/EphemerisDownloadModel.h b/code/sdk/application/wearable/n9/nativeapp/nativeui/ephemeris_download/include/EphemerisDownloadModel.h index 702f61e07..5e1001247 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/ephemeris_download/include/EphemerisDownloadModel.h +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/ephemeris_download/include/EphemerisDownloadModel.h @@ -39,6 +39,9 @@ namespace OHOS //获取有效期 bool GetValidityPeriod(); + // 定时器相关方法 + void ephemeris_data_timer(uint32_t interval); + void ephemeris_stop_data_timer(void); private: // 星历相关状态 diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/ephemeris_download/include/EphemerisDownloadPresenter.h b/code/sdk/application/wearable/n9/nativeapp/nativeui/ephemeris_download/include/EphemerisDownloadPresenter.h index 5e08d45ec..f498e7d9b 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/ephemeris_download/include/EphemerisDownloadPresenter.h +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/ephemeris_download/include/EphemerisDownloadPresenter.h @@ -1,21 +1,26 @@ #ifndef EPHEMERIS_DOWNLOAD_PRESENTER_H #define EPHEMERIS_DOWNLOAD_PRESENTER_H -#include "components/ui_view.h" -#include "key/include/KeyInputListener.h" #include "Presenter.h" +#include "View.h" +#include "key/include/KeyInputListener.h" #include "ephemeris_download/include/EphemerisDownloadModel.h" #include "ephemeris_download/include/EphemerisDownloadView.h" -#include "ModelListenerSample.h" namespace OHOS { class EphemerisDownloadModel; class EphemerisDownloadView; + + // Forward declarations for UI types + class UIView; + class RootView; + class ClickEvent; + class DragEvent; + class KeyEvent; class EphemerisDownloadPresenter : public Presenter, public UIView::OnClickListener, public RootView::OnKeyActListener, - public ModelListenerSample, public UIView::OnDragListener { public: @@ -24,10 +29,16 @@ namespace OHOS EphemerisDownloadPresenter(const EphemerisDownloadPresenter &) = delete; EphemerisDownloadPresenter &operator=(const EphemerisDownloadPresenter &) = delete; void OnResume() override; - void Notify() override; + void OnStop() override; bool OnClick(UIView &view, const ClickEvent &event) override; bool OnDrag(UIView &view, const DragEvent &event) override; bool OnKeyAct(UIView &view, const KeyEvent &event) override; + + // 静态实例获取方法 + static EphemerisDownloadPresenter* GetInstance(); + + // 供Model调用的回调函数 + void UpdateDownloadStatus(); }; } // OHOS diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/ephemeris_download/src/EphemerisDownloadModel.cpp b/code/sdk/application/wearable/n9/nativeapp/nativeui/ephemeris_download/src/EphemerisDownloadModel.cpp index 68ef854f6..e67a43b92 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/ephemeris_download/src/EphemerisDownloadModel.cpp +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/ephemeris_download/src/EphemerisDownloadModel.cpp @@ -1,9 +1,12 @@ #include "ephemeris_download/include/EphemerisDownloadModel.h" +#include "ephemeris_download/include/EphemerisDownloadPresenter.h" #include "custom_runtime.h" #include "custom_utils.h" #include "wearable_log.h" +#include "cmsis_os.h" +#include "service/graphic_service.h" #if defined(SUPPORT_GNSS) #include "gnss_http_server.h" @@ -106,4 +109,64 @@ std::string EphemerisDownloadModel::GetEphemerisValidityPeriod() { return ephemerisValidityPeriod; } +////////////////////////////////////////////////////////////////////////////////// +#define EPHEMERIS_TIMER_DATA 1 + +#if EPHEMERIS_TIMER_DATA +// 声明定时器变量 +static osTimerId_t g_data_timer = nullptr; + +static void ephemeris_data_callbackProc(int data) { + //更新下载进度 + if(OHOS::EphemerisDownloadPresenter::GetInstance()) { + OHOS::EphemerisDownloadPresenter::GetInstance()->UpdateDownloadStatus(); + } +} +static void ephemeris_data_timer_callback(int data) { + GraphicService::GetInstance()->PostGraphicEvent( + std::bind(ephemeris_data_callbackProc, data)); +} +void EphemerisDownloadModel::ephemeris_data_timer(uint32_t interval) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "EphemerisDownloadModel::ephemeris_data_timer"); + if (g_data_timer != nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Timer already exists!!"); + return; + } + g_data_timer = osTimerNew((osTimerFunc_t)ephemeris_data_timer_callback, + osTimerPeriodic, nullptr, nullptr); + if (g_data_timer == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer create failed!!"); + return; + } + int tick = osMs2Tick(interval); + osStatus_t ret = osTimerStart(g_data_timer, tick); + if (ret != osOK) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", + ret); + if (g_data_timer != nullptr) { + ret = osTimerDelete(g_data_timer); + } + g_data_timer = nullptr; + return; + } +} +void EphemerisDownloadModel::ephemeris_stop_data_timer(void) { + // 检查定时器是否存在 + if (g_data_timer != nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "EphemerisDownloadModel::ephemeris_stop_data_timer"); + osTimerStop(g_data_timer); + // 删除定时器并置为 nullptr + osStatus_t ret = osTimerDelete(g_data_timer); + if (ret != osOK) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "osTimerDelete failed, ret = %lx!!", ret); + } + g_data_timer = nullptr; + } +} +#endif + + } // namespace OHOS diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/ephemeris_download/src/EphemerisDownloadPresenter.cpp b/code/sdk/application/wearable/n9/nativeapp/nativeui/ephemeris_download/src/EphemerisDownloadPresenter.cpp index 7862d6291..88ef07c05 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/ephemeris_download/src/EphemerisDownloadPresenter.cpp +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/ephemeris_download/src/EphemerisDownloadPresenter.cpp @@ -10,18 +10,34 @@ #include "NativeAbility.h" #include "NativeRegisterManager.h" +#include "wearable_log.h" namespace OHOS { REGIST_SLICE(VIEW_EPHEMERIS_DOWNLOAD, EphemerisDownloadView, EphemerisDownloadPresenter); +// 静态实例变量 +static EphemerisDownloadPresenter* g_instance = nullptr; + EphemerisDownloadPresenter::EphemerisDownloadPresenter() { + g_instance = this; } EphemerisDownloadPresenter::~EphemerisDownloadPresenter() {} void EphemerisDownloadPresenter::OnResume() { RootView::GetInstance()->SetOnKeyActListener(this); + // 启动定时器 + EphemerisDownloadModel::GetInstance().ephemeris_data_timer(1000); // 1秒间隔 +} + +void EphemerisDownloadPresenter::OnStop() { + // 停止定时器 + EphemerisDownloadModel::GetInstance().ephemeris_stop_data_timer(); +} + +EphemerisDownloadPresenter* EphemerisDownloadPresenter::GetInstance() { + return g_instance; } bool EphemerisDownloadPresenter::OnClick(UIView &view, @@ -63,7 +79,8 @@ bool EphemerisDownloadPresenter::OnKeyAct(UIView &view, const KeyEvent &event) { return true; } -void EphemerisDownloadPresenter::Notify() { + +void EphemerisDownloadPresenter::UpdateDownloadStatus() { //根据下载状态更新视图 switch (EphemerisDownloadModel::GetInstance().GetEphemerisDownloadStatus()) { case EphemerisDownloadStatus::DOWNLOADING: @@ -115,14 +132,14 @@ void EphemerisDownloadPresenter::Notify() { } } break; - case EphemerisDownloadStatus::NOT_DOWNLOADED: - if (EphemerisDownloadView::GetInstance()) { - if (EphemerisDownloadView::GetInstance()->GetDownloadLabel()) { - EphemerisDownloadView::GetInstance()->GetDownloadLabel()->SetText( - "未下载"); - } - } - break; + // case EphemerisDownloadStatus::NOT_DOWNLOADED: + // if (EphemerisDownloadView::GetInstance()) { + // if (EphemerisDownloadView::GetInstance()->GetDownloadLabel()) { + // EphemerisDownloadView::GetInstance()->GetDownloadLabel()->SetText( + // "未下载"); + // } + // } + // break; } } diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/ephemeris_download/src/EphemerisDownloadView.cpp b/code/sdk/application/wearable/n9/nativeapp/nativeui/ephemeris_download/src/EphemerisDownloadView.cpp index fb9e6a357..d745b7a52 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/ephemeris_download/src/EphemerisDownloadView.cpp +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/ephemeris_download/src/EphemerisDownloadView.cpp @@ -13,6 +13,8 @@ static EphemerisDownloadView *g_pEphemerisDownloadView{nullptr}; EphemerisDownloadView::EphemerisDownloadView() { g_pEphemerisDownloadView = this; + //启动定时器 + EphemerisDownloadModel::GetInstance().ephemeris_data_timer(1000); } EphemerisDownloadView::~EphemerisDownloadView() { @@ -47,6 +49,8 @@ EphemerisDownloadView::~EphemerisDownloadView() { labelNote_ = nullptr; } g_pEphemerisDownloadView = nullptr; + //停止定时器 + EphemerisDownloadModel::GetInstance().ephemeris_stop_data_timer(); } void EphemerisDownloadView::OnStart() { @@ -87,7 +91,15 @@ bool EphemerisDownloadView::EphemerisDownloadInit() { } labelStatus_->SetPosition(90, 120, 300, 40); labelStatus_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 24); - labelStatus_->SetText("未下载"); + //如果有效期大于0,则显示下载成功 + if(EphemerisDownloadModel::GetInstance().GetValidityPeriod()) + { + labelStatus_->SetText("下载成功"); + } + else + { + labelStatus_->SetText("未下载"); + } labelStatus_->SetTextColor(Color::Yellow()); AddViewToRootContainer(labelStatus_); @@ -118,13 +130,13 @@ bool EphemerisDownloadView::EphemerisDownloadInit() { //如果有效期大于0,则不能下载 下载按键显示灰色;否则显示绿色 if(EphemerisDownloadModel::GetInstance().GetValidityPeriod()) { - // btnDownload_->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x5f)); - // btnDownload_->SetBackgroundColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x5f)); + btnDownload_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + btnDownload_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); } else { - // btnDownload_->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xff)); - // btnDownload_->SetBackgroundColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xff)); + btnDownload_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full); + btnDownload_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED); } AddViewToRootContainer(btnDownload_); -- 2.17.1