176 lines
5.2 KiB
C++
176 lines
5.2 KiB
C++
#include "sys_config.h"
|
|
#include "TjdUiAppWeatherAdapter.h"
|
|
#include "TjdUiMultiLanguageExt.h"
|
|
|
|
using namespace OHOS;
|
|
namespace TJD {
|
|
|
|
#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
|
|
|
|
static constexpr int16_t WEEK_LABEL_X = 69;
|
|
static constexpr int16_t ITEM_IMG_WIDTH = 43;
|
|
static constexpr int16_t ITEM_IMG_HEIGHT = 43;
|
|
static constexpr int16_t ITEM_LABEL_WIDTH = 220;
|
|
static constexpr int16_t ITEM_LABEL_HEIGHT = 91;
|
|
|
|
static constexpr int16_t NUM_20 = 20;
|
|
|
|
const char *select_week(Week weekday)
|
|
{
|
|
switch (weekday) {
|
|
case Week::SUNDAY:
|
|
return "周日";
|
|
case Week::MONDAY:
|
|
return "周一";
|
|
case Week::TUESDAY:
|
|
return "周二";
|
|
case Week::WEDNESDAY:
|
|
return "周三";
|
|
case Week::THURSDAY:
|
|
return "周四";
|
|
case Week::FRIDAY:
|
|
return "周五";
|
|
case Week::SATURDAY:
|
|
return "周六";
|
|
default:
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
/*----------------------------------------- TjdWeatherItemView class definition ---------------------------------------------*/
|
|
|
|
TjdWeatherItemView::TjdWeatherItemView()
|
|
{
|
|
SetPosition(8, 0, 325, ITEM_LABEL_HEIGHT);
|
|
SetUpChild();
|
|
Add(&icon_);
|
|
Add(&label1_);
|
|
Add(&label2_);
|
|
Add(&weekLabel_);
|
|
Add(&lowTempLabel_);
|
|
Add(&highTempLabel_);
|
|
}
|
|
|
|
TjdWeatherItemView::~TjdWeatherItemView()
|
|
{
|
|
Remove(&icon_);
|
|
Remove(&icon_);
|
|
Remove(&label1_);
|
|
Remove(&label2_);
|
|
Remove(&weekLabel_);
|
|
Remove(&lowTempLabel_);
|
|
Remove(&highTempLabel_);
|
|
}
|
|
|
|
void TjdWeatherItemView::SetUpChild()
|
|
{
|
|
weekLabel_.SetPosition(WEEK_LABEL_X, 0);
|
|
weekLabel_.SetFont(TJD_VECTOR_FONT_FILENAME, 34);
|
|
weekLabel_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
|
|
weekLabel_.SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
|
|
|
|
lowTempLabel_.SetPosition(197, 0);
|
|
lowTempLabel_.SetFont(TJD_VECTOR_FONT_FILENAME, 28);
|
|
lowTempLabel_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
|
|
lowTempLabel_.SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
|
|
|
|
label1_.SetPosition(197+30, 0);
|
|
label1_.SetFont(TJD_VECTOR_FONT_FILENAME, 28);
|
|
label1_.SetText("/");
|
|
label1_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
|
|
label1_.SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
|
|
|
|
highTempLabel_.SetPosition(197+30+21, 0);
|
|
highTempLabel_.SetFont(TJD_VECTOR_FONT_FILENAME, 28);
|
|
highTempLabel_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
|
|
highTempLabel_.SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
|
|
|
|
label2_.SetPosition(273, 0);
|
|
label2_.SetFont(TJD_VECTOR_FONT_FILENAME, 28);
|
|
label2_.SetText("°C");
|
|
label2_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
|
|
label2_.SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
|
|
|
|
icon_.SetPosition(351, (ITEM_LABEL_HEIGHT-ITEM_IMG_HEIGHT)/2);
|
|
icon_.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE);
|
|
icon_.SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
|
|
icon_.Resize(ITEM_IMG_WIDTH, ITEM_IMG_HEIGHT);
|
|
icon_.SetAutoEnable(false);
|
|
icon_.SetResizeMode(UIImageView::CENTER);
|
|
}
|
|
|
|
void TjdWeatherItemView::SetItemInfo(const WeatherItem &itemInfo)
|
|
{
|
|
itemInfo_ = itemInfo;
|
|
if (itemInfo.icon == nullptr) {
|
|
static_print_error("%s: itemInfo.icon nullptr", __func__);
|
|
} else {
|
|
icon_.SetSrc(itemInfo.icon);
|
|
}
|
|
|
|
weekLabel_.SetText(select_week(itemInfo.weekDay));
|
|
lowTempLabel_.SetText(std::to_string(itemInfo.lowTemperature).c_str());
|
|
highTempLabel_.SetText(std::to_string(itemInfo.highTemperature).c_str());
|
|
}
|
|
|
|
/*----------------------------------------- TjdWeatherAdapter class definition ---------------------------------------------*/
|
|
TjdWeatherAdapter::TjdWeatherAdapter() {}
|
|
|
|
TjdWeatherAdapter::~TjdWeatherAdapter()
|
|
{
|
|
listData_.clear();
|
|
}
|
|
|
|
uint16_t TjdWeatherAdapter::GetCount(void)
|
|
{
|
|
return listData_.size();
|
|
}
|
|
|
|
void TjdWeatherAdapter::ClearItem(void)
|
|
{
|
|
listData_.clear();
|
|
}
|
|
|
|
UIView *TjdWeatherAdapter::GetView(UIView *inView, int16_t index)
|
|
{
|
|
if (index >= (int16_t)listData_.size() || index < 0) {
|
|
return nullptr;
|
|
}
|
|
|
|
std::list<WeatherItem>::iterator it = listData_.begin();
|
|
for (int i = 0; i < index; i++) {
|
|
it++;
|
|
}
|
|
WeatherItem itemData = *it;
|
|
|
|
TjdWeatherItemView *item = nullptr;
|
|
if (inView == nullptr) {
|
|
item = new TjdWeatherItemView();
|
|
if (item == nullptr) {
|
|
return nullptr;
|
|
}
|
|
} else {
|
|
item = static_cast<TjdWeatherItemView *>(inView);
|
|
}
|
|
|
|
item->SetItemInfo(itemData);
|
|
return item;
|
|
}
|
|
|
|
void TjdWeatherAdapter::AddListItem(const WeatherItem &item)
|
|
{
|
|
listData_.push_back(item);
|
|
}
|
|
|
|
} |