mcu_hi3321_watch/tjd/ui/app/weather/TjdUiAppWeatherPresenter.cpp
2025-05-26 20:15:20 +08:00

158 lines
5.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "TjdUiAppWeatherPresenter.h"
#include "TjdUiAppMainView.h"
#include "TjdUiAppWeatherView.h"
#include "TjdUiRegisterManager.h"
#include "dock/input_device.h"
#include "limits.h"
#include "rtc_api.h"
#include "stdio.h"
#include "sys_config.h"
#include <cmath>
#include <iostream>
using namespace OHOS;
#define ENABLE_PRINT_INFO 1
#if ENABLE_PRINT_INFO
#define static_print_info(...) sys_ui_log_i(__VA_ARGS__) // 一般信息打印宏控制
#define static_print_warn(...) sys_ui_log_w(__VA_ARGS__) // 警告信息打印一般常开
#define static_print_error(...) sys_ui_log_e(__VA_ARGS__) // 错误信息打印一般常开
#define static_print_debug(...) sys_ui_log_d(__VA_ARGS__) // 调试信息打印
#else
#define static_print_info(...)
#define static_print_warn(...)
#define static_print_error(...)
#define static_print_debug(...)
#endif
namespace TJD {
TJD_REGIST_NATIVE_MENU(TJD_APP_VIEW_WEATHER, TjdUiAppWeatherView, TjdUiAppWeatherPresenter, IMG_MENU_LIST_MENU_WEATHER,
STR_ID_11);
static TjdUiAppWeatherPresenter *g_pvAppWeatherPresenter = nullptr;
TjdUiAppWeatherPresenter::TjdUiAppWeatherPresenter()
{
g_pvAppWeatherPresenter = this;
model = &TjdUiAppWeatherModel::GetInstance();
}
TjdUiAppWeatherPresenter::~TjdUiAppWeatherPresenter() { g_pvAppWeatherPresenter = nullptr; }
TjdUiAppWeatherPresenter *TjdUiAppWeatherPresenter::GetInstance(void) { return g_pvAppWeatherPresenter; }
void TjdUiAppWeatherPresenter::OnStart()
{
static_print_info("[TjdUiAppWeatherPresenter]::%s", __func__);
TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(this, KeyModelType::APP_KEY_TYPE);
//当前无法得知是否有无当天天气信息,先直接显示天气信息
if (GetWeatherModel()->GetDataValid() && !GetWeatherModel()->IsNeedUpdateWeather()) {
view_->UpdateSunPosition();
view_->UpdateWeekWeatherInfo();
} else {
if (GetWeatherModel()->GetBtLinkStatus()) {
view_->ChangedView(MINDPAGE, SWIPEPAGE);
} else
view_->ChangedView(NO_CONNECT_PAGE, SWIPEPAGE);
}
}
void TjdUiAppWeatherPresenter::OnResume()
{
static_print_info("[TjdUiAppWeatherPresenter]::%s", __func__);
if (view_->GetSwipeView()) {
view_->GetSwipeView()->RequestFocus();
view_->GetSwipeView()->SetRotateFactor(1.0);
}
Presenter<TjdUiAppWeatherView>::OnResume();
}
void TjdUiAppWeatherPresenter::OnPause()
{
static_print_info("[TjdUiAppWeatherPresenter]::%s", __func__);
if (view_->GetSwipeView()) {
view_->GetSwipeView()->ClearFocus();
}
Presenter<TjdUiAppWeatherView>::OnPause();
}
void TjdUiAppWeatherPresenter::OnStop()
{
static_print_info("[TjdUiAppWeatherPresenter]::%s", __func__);
TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(KeyModelType::APP_KEY_TYPE);
}
void TjdUiAppWeatherPresenter::OnSwipe(UISwipeView &view)
{
static_print_info("swipeView page:%d", view.GetCurrentPage());
}
bool TjdUiAppWeatherPresenter::OnDragStart(UIView &view, const DragEvent &event)
{
return TjdUiScreenDragListener::OnDragStart(view, event);
}
bool TjdUiAppWeatherPresenter::OnDrag(UIView &view, const DragEvent &event)
{
return TjdUiScreenDragListener::OnDrag(view, event);
}
bool TjdUiAppWeatherPresenter::OnDragEnd(UIView &view, const DragEvent &event)
{
return TjdUiScreenDragListener::OnDragEnd(view, event);
}
bool TjdUiAppWeatherPresenter::OnKeyAct(OHOS::UIView &view, const OHOS::KeyEvent &event)
{
if (!TjdUiCommonOnKeyListener::CheckIsExitEvent(event)) {
return true;
}
ExitWeatherView();
return false;
}
uint32_t TjdUiAppWeatherPresenter::GetCurTimeIndex(void)
{
struct rtc_time local_time;
struct rtc_class_ops *handel = tjd_driver_rtc_get_ops();
handel->get_rtc_time(&local_time);
if (local_time.tm_hour >= 6 && local_time.tm_hour <= 18) {
return local_time.tm_hour - 6;
}
if (local_time.tm_hour >= 19) {
return 12;
} else if (local_time.tm_hour >= 0 && local_time.tm_hour < 6) {
return 0;
}
return 0xff;
}
Point TjdUiAppWeatherPresenter::GetPointOnSemicircle(int16_t index, int16_t center_x, int16_t center_y, int16_t radius)
{
Point point;
// 将index转换为弧度index从0到12对应角度从0到π
double angle = index * M_PI / 12.0;
// 计算x和y坐标
// 由于屏幕坐标是整数,需要对结果进行四舍五入或取整
point.x = center_x - (int)round(radius * cos(angle));
static_print_debug("cos(%f) = %f ", angle, cos(angle));
point.y = center_y - (int)round(radius * sin(angle));
static_print_debug("sin(%f) = %f ", angle, cos(angle));
static_print_debug("point.x:%d point.y:%d", point.x, point.y);
return point;
}
void TjdUiAppWeatherPresenter::ExitWeatherView(void) { OHOS::NativeAbility::GetInstance().ChangePreSlice(); }
void TjdUiAppWeatherPresenter::UpdateViewInfo(void) { view_->UpdateCurWeatherInfo(); }
} // namespace TJD