//获取有效期
bool GetValidityPeriod();
+ // 定时器相关方法
+ void ephemeris_data_timer(uint32_t interval);
+ void ephemeris_stop_data_timer(void);
private:
// 星历相关状态
#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<EphemerisDownloadView, EphemerisDownloadModel>,
public UIView::OnClickListener,
public RootView::OnKeyActListener,
- public ModelListenerSample,
public UIView::OnDragListener
{
public:
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
#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"
EphemerisDownloadModel::~EphemerisDownloadModel() {}
-// void EphemerisDownloadModel::DownloadEphemeris() {}
//获取有效期接口
bool EphemerisDownloadModel::GetValidityPeriod() {
#if defined(SUPPORT_GNSS)
#endif
ephemerisDownloadStatus = EphemerisDownloadStatus::DOWNLOADING;
#if defined(SUPPORT_GNSS)
- uapi_gnss_start_agnss_download();
+ uapi_gnss_start_agnss_download();
#endif
}
/*
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
#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,
return true;
}
-void EphemerisDownloadPresenter::Notify() {
+
+void EphemerisDownloadPresenter::UpdateDownloadStatus() {
//根据下载状态更新视图
switch (EphemerisDownloadModel::GetInstance().GetEphemerisDownloadStatus()) {
case EphemerisDownloadStatus::DOWNLOADING:
}
}
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;
}
}
EphemerisDownloadView::EphemerisDownloadView() {
g_pEphemerisDownloadView = this;
+ //启动定时器
+ EphemerisDownloadModel::GetInstance().ephemeris_data_timer(1000);
}
EphemerisDownloadView::~EphemerisDownloadView() {
labelNote_ = nullptr;
}
g_pEphemerisDownloadView = nullptr;
+ //停止定时器
+ EphemerisDownloadModel::GetInstance().ephemeris_stop_data_timer();
}
void EphemerisDownloadView::OnStart() {
}
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_);
btnDownload_->SetOnClickListener(presenter_);
//如果有效期大于0,则不能下载 下载按键显示灰色;否则显示绿色
- // if(EphemerisDownloadModel::GetInstance().GetValidityPeriod())
- // {
- // btnDownload_->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x5f));
- // btnDownload_->SetBackgroundColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x5f));
- // }
- // else
- // {
- // btnDownload_->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xff));
- // btnDownload_->SetBackgroundColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xff));
- // }
+ if(EphemerisDownloadModel::GetInstance().GetValidityPeriod())
+ {
+ btnDownload_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full);
+ btnDownload_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED);
+ }
+ else
+ {
+ btnDownload_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full);
+ btnDownload_->SetStyleForState(STYLE_BACKGROUND_COLOR, Color::Black().full, UIButton::PRESSED);
+ }
AddViewToRootContainer(btnDownload_);